cwendt94 / espn-api

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

IndexError: list index out of range when importing new League #22

Closed kstreepy closed 5 years ago

kstreepy commented 5 years ago

IndexError Traceback (most recent call last)

in ----> 1 league_was_18 = League(was_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) 74 self._fetch_settings() 75 self._fetch_players() ---> 76 self._fetch_teams() 77 self._fetch_draft() 78 ~\Anaconda3\lib\site-packages\ff_espn_api\league.py in _fetch_teams(self) 119 member = None 120 break --> 121 elif member['id'] == team['owners'][0]: 122 break 123 roster = team_roster[team['id']] IndexError: list index out of range
cwendt94 commented 5 years ago

Are the two leagues full? For that error to happen there is a team ID in the Team endpoint that is not in the Roster endpoint which seems odd to me.

kstreepy commented 5 years ago

That's likely the issue, but I can't validate it. This is 2018 season, and between 2018 and 2019 we had some owner changes. It's possible we had slots open when league year changed as we had a 3 week window between owners leaving and new ones joining. ESPN won't let me view the 'Members' page for a 2018 league to confirm.

cwendt94 commented 5 years ago

That's interesting especially since the 2018 season is over and the data shouldn't change after that. I will look into a fix to make sure it does not crash.

If your able to attached the data for these two endpoints below for the league that is crashing, it would help me a ton!

insert your league id for "league_id".

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

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

Those endpoints shouldn't have any sensitive data in them.

kstreepy commented 5 years ago

553759.roster.txt 553759.team.txt

Here you go. Thanks for looking into this!

cwendt94 commented 5 years ago

Perfect, I will try to work on it in the next couple days!

cwendt94 commented 5 years ago

@kstreepy I believe branch #24 should fix this issue. When you have time would you be able to pull branch #24 down and try using ff_espn_api with your league that it was crashing on?

I want to make sure there is no other errors!

kstreepy commented 5 years ago

Will test this tonight and give you an update!

kstreepy commented 5 years ago

I'll be honest, I tried to figure out how to pull the specific branch with no luck. Happy to do it to test, but need some guidance on what the command would be. I've been trying variations of pip install git+https://github.com/cwendt94/ff-espn-api.git@[] but can't find the correct code to replace the brackets. Thanks in advance.

cwendt94 commented 5 years ago

No worries. So if run the commands below then use python3 inside the directory it will use that braches ff_espn_api package.

be inside ff-espn-api folder using command line

ff-espn-api$ git pull origin
ff-espn-api$ git branch -a
* master
  remotes/origin/AddDraftFeature#2
  remotes/origin/FreeAgencyList#18
  remotes/origin/FreeAgentFilters
  remotes/origin/HEAD -> origin/master
  remotes/origin/KeyErrorPlayerNotDrafted
  remotes/origin/TeamOwnerFieldEmpty#22
  remotes/origin/master
ff-espn-api$ git checkout TeamOwnerFieldEmpty#22
Branch 'TeamOwnerFieldEmpty#22' set up to track remote branch 'TeamOwnerFieldEmpty#22' from 'origin'.
Switched to a new branch 'TeamOwnerFieldEmpty#22'
ff-espn-api$ git branch
* TeamOwnerFieldEmpty#22
  master

Now from the directory you should be able to run the python3 cli and it will use the directories ff_espn_api package over the global one.

kstreepy commented 5 years ago

Thanks for the steps. Was able to import the problematic league from this branch.

cwendt94 commented 5 years ago

Awesome! So no errors?

kstreepy commented 5 years ago

Correct!