Open Phloot opened 4 years ago
Hmm, something is weird with that league. You are part of the league but the first team in the league doesn't exist. Are you able to to construct a league object for the league?
lg = yfa.League(oauth, '39.l.15338')
lg.teams()
Is your team key object an array still? I had to concatenate mine into a string like this:
def yahoo_login():
print("-- Logging to into Yahoo")
oauth = OAuth2(None, None, from_file='oauth.json')
game = yfa.Game(oauth, 'nfl')
print("-- Logged in to Yahoo")
game_id_array = game.league_ids(year=2020)
game_id_str = ''.join(map(str, game_id_array))
league = yfa.League(oauth, game_id_str)
print("-- Created local Yahoo league to extract info from")
return league
So that it would work properly, doesn't look as clean but works!
@Demon-tk, league_ids
returns an array in case you are in multiple leagues. What you have above only works if you are in a single league. You can just as easily reference the first element in the array and pass that through when creating the League
object. @Phloot opened the issue because the league_ids
call dies with a bad response from Yahoo!
I got a similar error with similar code.
gm = yfa.Game(sc=oauth, code="nfl")
league_ids = gm.league_ids(2024)
Trying to get leagues for 2024 and it has been working fine until one user got this exception. For other users, it's been working fine.
league_ids = gm.league_ids(year)
File "/usr/local/lib/python3.10/dist-packages/yahoo_fantasy_api/game.py", line 55, in league_ids
t = objectpath.Tree(self.yhandler.get_teams_raw())
File "/usr/local/lib/python3.10/dist-packages/yahoo_fantasy_api/yhandler.py", line 68, in get_teams_raw
return self.get("users;use_login=1/games/teams")
File "/usr/local/lib/python3.10/dist-packages/yahoo_fantasy_api/yhandler.py", line 25, in get
raise RuntimeError(response.content)
RuntimeError: b'{\n "error": {\n "xml:lang": "en-us",\n "yahoo:uri": "\\/fantasy\\/v2\\/users;use_login=1\\/games\\/teams?format=json",\n "description": "Team key 39.l.53239.t.8 does not exist.",\n "detail": ""\n }\n}'
@spilchen - I wonder if some Yahoo users have corrupt data in their accounts?
Do you think there's a way for these users to log into their Yahoo accounts and fix the bad data?
If so, please let me know. Then I can give this user some instructions on how to resolve it.
I resolved by querying the Yahoo API directly because I am filtering by NFL and season. One request returns all the league info that I need.
When attempting to return league_ids with a year specified, a RuntimeError is returned.
Code:
Returns:
I am able to successfully return league information, team information, etc if I manually input the league ID, however it makes it much more difficult to automate the querying of data if I manually need to identify the game ID for the current year (it is 399 for 2020 NFL for example) and league ID.
I also do not recognize the game ID (39), or league ID (15338) being returned in the traceback.
Any thoughts?