diff --git a/espn_api/base_league.py b/espn_api/base_league.py index 3574c0d3..d89c5d81 100644 --- a/espn_api/base_league.py +++ b/espn_api/base_league.py @@ -84,8 +84,9 @@ def _get_pro_schedule(self, scoringPeriodId: int = None): pro_team_schedule = {} for team in pro_teams: - if team['id'] != 0 and (str(scoringPeriodId) in team['proGamesByScoringPeriod'].keys() and team['proGamesByScoringPeriod'][str(scoringPeriodId)]): - game_data = team['proGamesByScoringPeriod'][str(scoringPeriodId)][0] + pro_game = team.get('proGamesByScoringPeriod', {}) + if team['id'] != 0 and (str(scoringPeriodId) in pro_game.keys() and pro_game[str(scoringPeriodId)]): + game_data = pro_game[str(scoringPeriodId)][0] pro_team_schedule[team['id']] = (game_data['homeProTeamId'], game_data['date']) if team['id'] == game_data['awayProTeamId'] else (game_data['awayProTeamId'], game_data['date']) return pro_team_schedule diff --git a/espn_api/football/league.py b/espn_api/football/league.py index 628782f7..e4d3dd7d 100644 --- a/espn_api/football/league.py +++ b/espn_api/football/league.py @@ -74,7 +74,7 @@ def _get_positional_ratings(self, week: int): 'scoringPeriodId': week, } data = self.espn_request.league_get(params=params) - ratings = data['positionAgainstOpponent']['positionalRatings'] + ratings = data.get('positionAgainstOpponent', {}).get('positionalRatings', {}) positional_ratings = {} for pos, rating in ratings.items():