Python Forum
KeyError while retrieving ESPN data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KeyError while retrieving ESPN data
#1
I'm a novice to python3, but a former developer. I've installed python3 on my MacBook Pro and I've accessed ESPN Fantasy Football database via Terminal. I'm using Visual Studio Code to run the following:
Successful:
import pandas as pd
import espnfantasyfootball as espn
import espnsecrets
league = espn.FantasyLeague(league_id=999999,year=2023,swid=espnsecrets.swid, espn_s2=espnsecrets.espn_s2)
Error when running:
data = league.get_league_data()

Error:
KeyError Traceback (most recent call last) /Users/owner/Library/Mobile Documents/com~apple~CloudDocs/Documents/fantasyfootball.ipynb Cell 3 line 1 ----> 1 mydata = league.get_league_data() File /usr/local/lib/python3.11/site-packages/espnfantasyfootball/espnfantasyfootball.py:205, in FantasyLeague.get_league_data(self, week) 203 for week in weeks: 204 league_json = self.load_league(week) --> 205 self.load_player_data(league_json, week) 206 self.load_team_names(week) 208 # After loading the data for the week, add a copy of the DataFrame to the list. File /usr/local/lib/python3.11/site-packages/espnfantasyfootball/espnfantasyfootball.py:65, in FantasyLeague.load_player_data(self, league_json, week) 61 weeks = [] 64 # Loop through each team ---> 65 for team in range(0, len(league_json['teams'])): 66 67 # Loop through each roster slot in each team 68 for slot in range(0, len(league_json['teams'][team]['roster']['entries'])): 69 # Append the week number to a list for each entry for each team 70 weeks.append(week) KeyError: 'teams'
Any help would be greatly appreciated.
Larz60+ write Nov-21-2023, 10:16 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I have added the tags for this post. Please use BBCode tags on future posts.
Reply
#2
issues if look ar code so was it made 5-6 month ago,
the API may have changed and author has not update it.
Look for other eg ESPN API, Using ESPN's new Fantasy API (v3).
Reply
#3
Thanks @snippsat. So, based on the links you shared, should I go back to Terminal and run another command to get the ESPN dataset, then run my same code? The examples I see in the links are URLs and not Terminal commands. Thanks in advance.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  .get() not retrieving value? Sedos101 2 572 Aug-25-2023, 11:48 AM
Last Post: deanhystad
  [Solved] Retrieving a pdf from sqlite3 BigMan 4 2,342 Mar-12-2022, 01:56 PM
Last Post: deanhystad
  Retrieving a column from a data set using a function Bayle 6 2,361 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Retrieving Cookies whois1230 2 2,190 Nov-21-2020, 12:01 PM
Last Post: snippsat
  Problem: Retrieving Form data PythonDev 3 3,117 Oct-16-2020, 02:09 AM
Last Post: PythonDev
  Retrieving dictionary keys within with another dictionay bazcurtis 8 2,857 Oct-29-2019, 10:06 PM
Last Post: bazcurtis
  Retrieving items from JSON bazcurtis 12 5,078 Oct-27-2019, 05:18 PM
Last Post: bazcurtis
  Trouble retrieving dictionary from mysql.connector cursor swechsler 2 3,067 Sep-17-2019, 05:21 PM
Last Post: swechsler
  retrieving pvalue from statsmodels results Staph 4 3,042 Jul-18-2019, 03:27 PM
Last Post: Gribouillis
  PRAW and PyQt: Immense slowdown when retrieving Reddit posts and adding them to GUI codebro 2 3,236 Dec-30-2018, 01:19 AM
Last Post: codebro

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020