uberfastman / yfpy

Python API wrapper for the Yahoo Fantasy Sports public API (supports NFL, NHL, MLB, and NBA).
https://pypi.org/project/yfpy/
GNU General Public License v3.0
178 stars 46 forks source link

HTTPError: 400 on yahoo_query.get_league_players() call #21

Closed austinbeauch closed 2 years ago

austinbeauch commented 2 years ago

HTTPError: 400 Client Error: Bad Request for url: https://fantasysports.yahooapis.com/fantasy/v2/league/411.l.****/players;start=1425?format=json

Not sure why this is popping up. Running the same script for a few days and only now is this throwing me an error. I don't think it's a data limit error since it's not 999 like the source comments suggest.

Anyone experiencing the same thing? I might give it another 24hrs and then dig into it some more.

uberfastman commented 2 years ago

Hmm. A few thoughts pop out @austinbeauch… first, unless you intentionally censored your league ID, then that request URL will fail with the asterisks.

However if that was just you, I will say that I only just updated the functionality to iterate through all players 25 at a time and retrieve them all, as I’d been missing that before. I tested it but it’s possible something about an end condition where it gets to the last players is not catching and stopping correctly.

What fantasy sport are you retrieving players for?

austinbeauch commented 2 years ago

Thank for the speedy reply @uberfastman! That was indeed me who censored the league id. This is for hockey. I'm on the most recent version as well. It's weird because it's been working fine until last night/today. Could be more players were added to the league and it's creating a new edge case.

I know you developed this mainly focusing on NFL. If this seems to be NHL specific right now I can try and see what's causing it later day, just wanted to see if I was alone in experiencing this or not!

uberfastman commented 2 years ago

No problem @austinbeauch, I’ll test it later on in one of my old hockey leagues and see if I can reproduce it. I definitely only tested the new functionality for NFL, but there’s no reason it shouldn’t work for NHL/NBA/MLB.

austinbeauch commented 2 years ago

Just a quick update as I'm working through this: this appears to not be an issue with some sort of end-of-list case. For whatever reason it's only at start=1425 that it throws an error. Skipping to start=1450 works. Something wonky is going on in that call. Something tells me that this is more an issue on Yahoo's end. I'll keep looking

austinbeauch commented 2 years ago

Yep, looks like Yahoo is getting upset that one of its own players "doesn't exist"

'Player key 411.p.8205 does not exist.'

Is the description of the returned response. Rather strange, considering he does exist, but not on the website players list.

When sorting all players available, it'll put plays with equal points in chronological order of their ID's. So everyone with zero points is sorted by increasing ID until the players with negative points. Viel hasn't played this year and should have zero points, but Kristians Rubins has an ID of 8191, so Viel at 8205 should come after, but he's absent from the list. However Viel does exist if you search him up manually.

image

Something strange is going on with Yahoo's API, Viel is somehow dropped from their list of players. I'm not sure exactly what the best way of handling this would be, since an easy solution would be to just ignore those 25 players, but it's possible someone important exists there. Could be worth it to contact Yahoo? Looks like they have an active rep on Reddit, u/YahooFantasyCare, that can report bugs to the engineering teams.

uberfastman commented 2 years ago

Wow thanks @austinbeauch you did all the hard work for me! I was just getting on to take a look at this (I was traveling yesterday), and here you've already discovered the issue! Unfortunately the is not the first time Yahoo's API has had some questionable issues... I've been working with it for like 7 years and it's always been a mess.

Anyway, I'm gonna take a look at the player response for that particular request and see if I can implement some sort of error handling for this annoying edge case that will then retrieve all players that DO exist within that 25 player block and ignore failures.

Pensfan66 commented 2 years ago

Kind of a similar issue, however I believe mine is an expired token issue.

What I'm trying to do is run the test_get_league_scoreboard_by_week() function on a thread in order to push live updates (every 30 sec) to a led matrix. So far it works flawlessly for about an hour and then 401 errors repeating. I restart the code and everything runs as it should for another hour until I hit 401's again. Looked into this in YF api documentation and it checks out that the token expires every hour.

Any thoughts on how I could code a refresh into the 401 error try/except portion? Or any thoughts in general on getting around this?

uberfastman commented 2 years ago

@Pensfan66 if you don't mind, could you open a separate issue for the token refresh? That seems like a reasonable update to make, but just for the sake of keeping things somewhat organized I'd appreciate having a separate thread for it.

uberfastman commented 2 years ago

@austinbeauch I've implemented a fix for this issue you've found in v4.1.1, in #23. Now when retrieving all players, if it fails on one of the requests it will attempt to individually retrieve all players in that request and simply skip failed players, and log the failures. Give it a whirl and see how it works for you. If any other problems arise regarding this, just reopen this issue.

austinbeauch commented 2 years ago

Looks like it's working, thanks a ton for your effort!!

uberfastman commented 2 years ago

@austinbeauch fantastic, glad we got it sorted! You did the hard leg work figuring it out after all, I just had to implement the workaround haha.