Open crawles opened 7 years ago
PlayerPosition
is a required parameter for this endpoint. If you change your url to http://stats.nba.com/stats/shotchartdetail?Period=0&VsConference=&LeagueID=00&LastNGames=0&TeamID=0&Position=&Location=&Outcome=&ContextMeasure=FGA&DateFrom=&StartPeriod=&DateTo=&OpponentTeamID=0&ContextFilter=&RangeType=&Season=2015-16&AheadBehind=&PlayerID=201939&EndRange=&VsDivision=&PointDiff=&RookieYear=&GameSegment=&Month=0&ClutchTime=&StartRange=&EndPeriod=&SeasonType=Regular+Season&SeasonSegment=&GameID=&PlayerPosition=
(note this final query parameter) it should work.
Before trying to decode the JSON of the request, I'd recommend checking the status code and printing the response body if not a 400 -- unfortunately the NBA's API sends back non-JSON error messages when something goes wrong. They are however pretty informative.
Ah awesome. Thank you @nickb1080!!
Updated the wiki about for the stats.nba.com api. Think this is a relatively recent change as I've come across this problem following multiple tutorials.
@bttmly I tried your request link in the browser adding PlayerPosition=Guard, it returned "
@zgvidwck Hmm. Yeah it's returning a 500 error; seems like an issue on their end. If you try it with an invalid parameter (like PlayerPosition as "G") it returns a 400 that says "Forward" "Guard" and "Center" are valid values. So according to their own error messages it should work.
The shot chart API is a pain. If you can, the most effective thing to do is just download all the data in bulk (set PlayerID to 0
) and slice and dice it as you please, or load it into your own database.
@bttmly I found a solution on reddit. Adding "&CFID=" to the parameters, it worked.
@zgvidwck huh! can you post the link to the reddit thread? I have a package that intends to document all required parameters for each endpoint so I should probably add that one
thanks
I tried this solution and I am still getting an 500 error if anyone could clarify this that would be great thanks
Think it's a problem with NBA stats API?
ValueError Traceback (most recent call last)