cwendt94 / espn-api

ESPN Fantasy API! (Football, Basketball)
MIT License
628 stars 199 forks source link

KeyError: -1 when importing League #21

Closed kstreepy closed 5 years ago

kstreepy commented 5 years ago

I'm in 4 leagues. I received this error for 2 of the 4 leagues with the same lines indicated.

KeyError Traceback (most recent call last)

in ----> 1 league_dynasty_18 = League(dynasty_id, year18, espn_s2, swid) ~\Anaconda3\lib\site-packages\ff_espn_api\league.py in __init__(self, league_id, year, espn_s2, swid) 52 'SWID': self.swid 53 } ---> 54 self._fetch_league() 55 56 def __repr__(self): ~\Anaconda3\lib\site-packages\ff_espn_api\league.py in _fetch_league(self) 75 self._fetch_players() 76 self._fetch_teams() ---> 77 self._fetch_draft() 78 79 def _fetch_teams(self): ~\Anaconda3\lib\site-packages\ff_espn_api\league.py in _fetch_draft(self) 192 team = self.get_team_data(pick['teamId']) 193 playerId = pick['playerId'] --> 194 playerName = self.player_map[playerId] 195 round_num = pick['roundId'] 196 round_pick = pick['roundPickNumber'] KeyError: -1
cwendt94 commented 5 years ago

I am guessing because this is a dynasty league that if the player was carried over roundPickNumber does not exists

cwendt94 commented 5 years ago

It should be a easy fix but would be super helpfully if you could attach the data from the endpoint below for the league that it crashes on.

replace "league_id" with your league number.

http://fantasy.espn.com/apis/v3/games/FFL/seasons/2018/segments/0/leagues/league_id?view=mDraftDetail

This endpoint does not have any sensitive data.

dtcarls commented 5 years ago

https://fantasy.espn.com/football/league/draftrecap?leagueId=1483079 Round 6 pick 3 https://i.imgur.com/0iSZrql.png

kstreepy commented 5 years ago

http://fantasy.espn.com/apis/v3/games/FFL/seasons/2018/segments/0/leagues/51386?view=mDraftDetail

cwendt94 commented 5 years ago

@kstreepy I am not able to view your league because it is private. Are you able to copy the data to a file and upload it.

@dtcarls thanks for image and league id. I will try to have a fix out sometime this upcoming week!

kstreepy commented 5 years ago

@cwendt94 My apologies. JSON attached. 51386.txt

cwendt94 commented 5 years ago

@kstreepy Perfect, thank you!

cwendt94 commented 5 years ago

@kstreepy I ran that data with unit tests and it didn't crash or get a key error on mine which is strange.

@dtcarls the newest package should fix the player not found error.