Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONDecodeError when hitting endpoints #5

Closed
popo9192 opened this issue Oct 1, 2018 · 7 comments
Closed

JSONDecodeError when hitting endpoints #5

popo9192 opened this issue Oct 1, 2018 · 7 comments
Labels
question Inquiry from community

Comments

@popo9192
Copy link

popo9192 commented Oct 1, 2018

When I hit some of the endpoints it works for the first few calls, but then i get the following error every time i try:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Has anyone else been getting this?

@popo9192
Copy link
Author

popo9192 commented Oct 1, 2018

This is the line that is leaving errors:
score = boxscorescoringv2.BoxScoreScoringV2(game_id=game)

@swar
Copy link
Owner

swar commented Oct 2, 2018

What happens when you call the link in a web browser?

See valid link here: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/boxscorescoringv2.md

I have a feeling you're getting limited after a few calls.

@swar swar added the question Inquiry from community label Oct 2, 2018
@cclauss
Copy link
Contributor

cclauss commented Oct 4, 2018

The full error log , not just one line, would help us to find the line that is breaking.

@popo9192
Copy link
Author

popo9192 commented Oct 6, 2018

Here is the full error:

summary = boxscoresummaryv2.BoxScoreSummaryV2(game_id=game)
File "//anaconda/envs/nba_wizard/lib/python3.6/site-packages/nba_api/stats/endpoints/boxscoresummaryv2.py", line
17, in init
data_sets = self.nba_response.get_data_sets()
File "//anaconda/envs/nba_wizard/lib/python3.6/site-packages/nba_api/stats/library/http.py", line 73, in get_dat
a_sets raw_dict = self.get_dict()
File "//anaconda/envs/nba_wizard/lib/python3.6/site-packages/nba_api/library/http.py", line 38, in get_dict
return json.loads(self._response)
File "//anaconda/envs/nba_wizard/lib/python3.6/json/init.py", line 354, in loads
return _default_decoder.decode(s)
File "//anaconda/envs/nba_wizard/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "//anaconda/envs/nba_wizard/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@swar
Copy link
Owner

swar commented Oct 11, 2018

Did you run into the issue with the suggestion that I mentioned above?

From your error log, what's happening is that nothing is getting returned from the API requests. So when you try to load the raw JSON into a dictionary, it fails because nothing is not valid JSON. I believe I am correct in assuming that you're getting banned / limited after a few requests.

For error handling, I suggest using valid_json() to determine if the response returned is in valid JSON. If it is, then you can use get_dict() as you please. However, I suggest using time.sleep() to pause your script so that you're not sending so many requests at a time.

Let me know if you have any questions.

@xzs
Copy link

xzs commented Oct 17, 2018

As an FYI, it seems like NBA stats API is limiting users to 10 consecutive calls. I've been running a forked version of https://github.com/dblackrun/scrape_nba for the last 2 seasons to scrape the API to a local db with no issues, until today.

It seems like they've upped the restrictions this time around (in addition to adding https) even if you masked the USER-AGENT in the header

Here is a screenshot from logging my requests (ignore the SQLalchemy errors):

screen shot 2018-10-17 at 1 56 58 am

EDIT: as an interesting note. using time.sleep(5) to set a delay does seem to bypass this issue. I was able to scrape all data for both of today's games with this bypass.

@swar swar closed this as completed Dec 13, 2018
swar pushed a commit that referenced this issue Apr 15, 2019
Updated playbyplay_regex
@mrr358
Copy link

mrr358 commented Jan 22, 2023

I had the same error with this API and found the game_id I was using from another api call (playergamelog) was 8 chars long. I spotted on the API docs that the pattern required was ^\d{10}$ so I popped 2 leading '00' and it worked ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Inquiry from community
Projects
None yet
Development

No branches or pull requests

5 participants