swar / nba_api

An API Client package to access the APIs for NBA.com
MIT License
2.43k stars 524 forks source link

[Bug]: PlayerGamelogs getting advanced stats #346

Open Chase-Pagon opened 1 year ago

Chase-Pagon commented 1 year ago

NBA API Version

V1.2

Issue

I'm trying to get advanced box score stats for a player specifically this table but it seems that the request being called is invalid as I'm getting a JSON decoder error /usr/lib/python3.9/json/decoder.py in raw_decode(self, s, idx) 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err: --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Code

from nba_api.stats.endpoints import playergamelogs import pandas as pd

Use the PlayerGameLogs endpoint to get game logs for all players for a specific date

gamelogs = playergamelogs.PlayerGameLogs(measure_type_player_game_logs_nullable='advanced', player_id_nullable=2544, season_nullable='2021-22')

Get the data as a pandas DataFrame

gamelogs_df = gamelogs.get_data_frames()[0]

rsforbes commented 1 year ago

@Chase-Pagon - I took a look at this today.

To establish baseline, the call works when MeasureType is set to 'Base'. At the same time, additional values do not appear to be supported and will result in a 500 Internal Server Error.

My guess is "if" the other MeasureTypes are supported, then they are likely supported in some type of combination; meaning you have to have A set to a value before MeasureType B will work correctly. Just a guess though.

While "not a bug" I think we can do something better here. I'm going to mark this as "documentation" and "usability".

ChristopherBanas commented 1 year ago

I believe some playergamelogs, specifically non base ones, do not exist. I encountered this a lot and I discovered it's not an issue with this package, it's something that is occurring on nba.com as well. If you open up the dev tools and look at the network traffic on this page https://www.nba.com/stats/player/2544/boxscores-advanced?Season=2012-13, you'll see that the endpoint is failing there.

I have contacted the NBA a few times about dozens of pages like this but I have not heard back.

rsforbes commented 1 year ago

@ChristopherBanas - I ran through some manual testing this morning. The only Advanced setting I could find to work was the 2022-23 season, and only for the playoffs. Everything thing else was failing—something on the NBA's side.

I don't see where there is any difference in any call between Base and Advanced. In short, the ability to retrieve data with either call results in no change.

My thoughts: To avoid a breaking change, we keep the parameter but force it to use Base. This would allow the call to succeed and return the correct data (as there's no difference in the outcome).

Since you may have more experience with this endpoint, I certainly value your input.

Let me know what you think.

ChristopherBanas commented 1 year ago

That sounds good to me. I swear that this just started happening as it was never an issue until recently. I brought it up in the slack about 2 weeks ago when I first started noticing it. Discouraging that this is happening, I had to add a disclaimer to my site because as you said, almost all of the non Base stats seem to fail.

Hopefully they spend some time looking into this on their side now that the finals are over. Not sure what else can be done. Mentally I'll give them the rest of the summer before I start exploring third party APIs or building small web scrapers to get the data that NBA.com no longer provides.

ChristopherBanas commented 1 year ago

NBA might have fixed this? Looks like https://www.nba.com/stats/player/2544/boxscores-advanced?Season=2012-13 returns the data now instead of erroring out