cwendt94 / espn-api

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

KeyError: 'deadlineDate' when creating League object #10

Closed OD1995 closed 5 years ago

OD1995 commented 5 years ago

Attempting to follow this example code:

from ff_espn_api import League
league_id = 1234
year = 2018
swid = '{03JFJHW-FWFWF-044G}'
espn_s2 = 'ASCWDWheghjwwqfwjqhgjkjgegkje'
league = League(league_id, year, espn_s2, swid)

I got this error:


  File "<ipython-input-26-f3f7b9b05a45>", line 6, in <module>
    league = League(league_id, year, espn_s2, swid)

  File "C:\Users\Oli\AppData\Local\Continuum\anaconda3\lib\site-packages\ff_espn_api\league.py", line 49, in __init__
    self._fetch_league()

  File "C:\Users\Oli\AppData\Local\Continuum\anaconda3\lib\site-packages\ff_espn_api\league.py", line 69, in _fetch_league
    self._fetch_settings()

  File "C:\Users\Oli\AppData\Local\Continuum\anaconda3\lib\site-packages\ff_espn_api\league.py", line 145, in _fetch_settings
    self.settings = Settings(data['settings'])

  File "C:\Users\Oli\AppData\Local\Continuum\anaconda3\lib\site-packages\ff_espn_api\settings.py", line 9, in __init__
    self.trade_deadline = data['tradeSettings']['deadlineDate']

KeyError: 'deadlineDate'

I'm pretty confident I've got the correct swid and espn_s2 values for my league, although my espn_s2 is 300 characters long compared to the example one with 29 characters..

cwendt94 commented 5 years ago

Hi @OD1995 your swid and espn_s2 are correct else it would have thrown a access denied error. This bug looks like ESPN does not send a deadlineDate field if it is not set in the league. This should be an easy fix. Thank you for reporting this!

cwendt94 commented 5 years ago

I added the fix and tested it. I am going to push a new version of ff_espn_api. Let me know if you run into anymore errors.

kevenrc commented 5 years ago

I ran into a similar error that says:

File "/Users/kevenrc/Documents/fantasy/ff-espn-api/ff_espn_api/league.py", line 114, in _fetch_teams
    if member['id'] == team['owners'][0]:

when trying to create League object.

OD1995 commented 5 years ago

@cwendt94 Great, all fixed, thanks!

cwendt94 commented 5 years ago

@kevenrc Interesting so you are getting a key error for 'owners'? I will look into that. I would think owners key would always be in the data.

kevenrc commented 5 years ago

@cwendt94 could it be because I am trying to create the League object on a league that hasn't had a draft yet?

cwendt94 commented 5 years ago

I don't believe so because I can access my 2019 league. Is this a brand new league this year?

kevenrc commented 5 years ago

@cwendt94 Yes, it's a brand new league this year.

cwendt94 commented 5 years ago

Interesting, I am guessing with brand new leagues owners field is not given. I will look into this and come up with a fix!

dtcarls commented 5 years ago

Is the league full? This was a bug with espn_ff.

cwendt94 commented 5 years ago

@kevenrc The newest package should work if a team does not have a owner! Let me know if it fixes it and that there is not any other errors!