Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: HTTPSConnectionPool(host='stats.nba.com', port=443): Read timed out. (read timeout=30) #405

Open
ghadfield32 opened this issue Nov 15, 2023 · 3 comments
Labels
bug Something isn't working triage Researching into a possible bug

Comments

@ghadfield32
Copy link

NBA API Version

latest

Issue

I'm having the same kind of issue as described in this post for leaguegamefinder and playergamelog. Can you tell me where I'm going wrong in my api call? It's been working for NBA season so far as I've been running some models on this data until now. Just today it started giving me the timeout error.

Code

from nba_api.stats.endpoints import leaguegamefinder
import pandas as pd
import time
import requests

Custom headers to mimic a browser request

custom_headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
'Referer': 'https://stats.nba.com',
'Connection': 'keep-alive',
}

def get_games_by_season(season_year_start, retries=3, delay=30):
season_id = f"{season_year_start}-{str(season_year_start+1)[-2:]}"

for attempt in range(retries):
    try:
        gamefinder = leaguegamefinder.LeagueGameFinder(season_nullable=season_id)
        gamefinder.nba_api.client.headers = custom_headers
        gamefinder.nba_api.client.timeout = 60  # Reduced timeout

        games = gamefinder.get_data_frames()[0]
        return games
    except requests.exceptions.Timeout:
        print(f"Timeout for season {season_id}, retry {attempt+1}/{retries}. Waiting {delay} seconds...")
        time.sleep(600)  # Shorter delay before retrying
    except Exception as e:
        print(f"Error for season {season_id}: {e}")
        break

return pd.DataFrame()  # Empty DataFrame on failure

all_seasons_data = pd.DataFrame()

for year in range(2023, 2024):
season_data = get_games_by_season(year)
if not season_data.empty:
all_seasons_data = pd.concat([all_seasons_data, season_data], ignore_index=True)
else:
print(f"No data for season starting in {year}")

@ghadfield32 ghadfield32 added bug Something isn't working triage Researching into a possible bug labels Nov 15, 2023
@LeKD6
Copy link

LeKD6 commented Dec 26, 2023

Did you ever find a solution? Having the same issue myself, randomly stopped working

@SrijithVenkat
Copy link

Having this same issue as well

@erik-rt
Copy link

erik-rt commented May 9, 2024

+1 on this issue, anyone find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Researching into a possible bug
Projects
None yet
Development

No branches or pull requests

4 participants