cwendt94 / espn-api

ESPN Fantasy API! (Football, Basketball)
MIT License
655 stars 213 forks source link

Not able to fetch League info for 2025 anymore #612

Open ktshah04 opened 6 days ago

ktshah04 commented 6 days ago

Sport

Basketball

Summary

I use the following to fetch league info and it recently stopped working only on the current season (2025)

I am using Python 3.11.4 and espn-api 0.40.1. I am still able to use this code for years 2010-2024.

# Read in environment variables
import os

# Read in the environment variables
league_id = os.environ['LEAGUE_ID']
swid = os.environ['SWID']
espn_s2 = os.environ['ESPN_S2']

from espn_api.basketball import League as bball_league
league = bball_league(league_id, 2025, espn_s2, swid)

I get the following error

{
    "name": "KeyError",
    "message": "'stats'",
    "stack": "---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[2], line 5
      3 print(i)
      4 if i != 2021:
----> 5     league = bball_league(league_id, i, espn_s2, swid)
      6     league_info[i] = league
      7     # league_key = {}
      8     # league_key['season_year'] = i
      9     # league_key['num_teams'] = len(league.teams)
     10     # league_key['website'] = 'ESPN'
     11 
     12     # League.insert1(league_key)

File ~/.local/lib/python3.11/site-packages/espn_api/basketball/league.py:19, in League.__init__(self, league_id, year, espn_s2, swid, fetch_league, debug)
     16 super().__init__(league_id=league_id, year=year, sport='nba', espn_s2=espn_s2, swid=swid, debug=debug)
     18 if fetch_league:
---> 19     self.fetch_league()

File ~/.local/lib/python3.11/site-packages/espn_api/basketball/league.py:23, in League.fetch_league(self)
     21 def fetch_league(self):
     22     data = self._fetch_league()
---> 23     self._fetch_teams(data)
     24     super()._fetch_draft()
     26     self.BoxScoreClass = get_box_scoring_type_class(self.settings.scoring_type)

File ~/.local/lib/python3.11/site-packages/espn_api/basketball/league.py:50, in League._fetch_teams(self, data)
     48 '''Fetch teams in league'''
     49 pro_schedule = self._get_all_pro_schedule()
---> 50 super()._fetch_teams(data, TeamClass=Team, pro_schedule=pro_schedule)
     52 # replace opponentIds in schedule with team instances
     53 for team in self.teams:

File ~/.local/lib/python3.11/site-packages/espn_api/base_league.py:86, in BaseLeague._fetch_teams(self, data, TeamClass, pro_schedule)
     84     roster = team_roster[team['id']]
     85     owners = [member for member in members if member.get('id') in team.get('owners', [])]
---> 86     self.teams.append(TeamClass(team, roster=roster, schedule=schedule, year=seasonId, owners=owners, pro_schedule=pro_schedule))
     88 # sort by team ID
     89 self.teams = sorted(self.teams, key=lambda x: x.team_id, reverse=False)

File ~/.local/lib/python3.11/site-packages/espn_api/basketball/team.py:30, in Team.__init__(self, data, roster, schedule, year, **kwargs)
     27 if 'logo' in data:    
     28     self.logo_url = data['logo']
---> 30 self._fetch_roster(roster, year, kwargs.get('pro_schedule'))
     31 self._fetch_schedule(schedule)
     32 self.owners = kwargs.get('owners', [])

File ~/.local/lib/python3.11/site-packages/espn_api/basketball/team.py:44, in Team._fetch_roster(self, data, year, pro_schedule)
     41 roster = data['entries']
     43 for player in roster:
---> 44     self.roster.append(Player(player, year, pro_schedule))

File ~/.local/lib/python3.11/site-packages/espn_api/basketball/player.py:45, in Player.__init__(self, data, year, pro_team_schedule)
     43 game = self.schedule.get(id, {})
     44 self.stats[id] = dict(applied_total=applied_total, applied_avg=applied_avg, team=game.get('team', None), date=game.get('date', None))
---> 45 if split['stats']:
     46     if 'averageStats' in split.keys():
     47         self.stats[id]['avg'] = {STATS_MAP.get(i, i): split['averageStats'][i] for i in split['averageStats'].keys() if STATS_MAP.get(i) != ''}

KeyError: 'stats'"
}

Logs/Data

No response

lightsout7 commented 6 days ago

I am having the same issue!