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

json.decoder.JSONDecodeError #2

Open
mikan01 opened this issue Apr 3, 2020 · 7 comments
Open

json.decoder.JSONDecodeError #2

mikan01 opened this issue Apr 3, 2020 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@mikan01
Copy link

mikan01 commented Apr 3, 2020

Hi,

I keep getting this error after scraping few books (3 to 4 books). Please help

Traceback (most recent call last): File "main.py", line 62, in <module> audio_files = scraper.scrape_book_audio(driver, book_json) File "C:\Users\Fang Yuan\Downloads\blinkist-scraper-master\scraper.py", line 223, in scrape_book_audio audio_url = audio_request.json()['url'] File "C:\Python38\lib\site-packages\requests\models.py", line 888, in json return complexjson.loads( File "C:\Python38\lib\json\__init__.py", line 357, in loads return _default_decoder.decode(s) File "C:\Python38\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python38\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@leoncvlt leoncvlt self-assigned this Apr 3, 2020
@leoncvlt leoncvlt added the bug Something isn't working label Apr 3, 2020
@leoncvlt
Copy link
Owner

leoncvlt commented Apr 3, 2020

I could not replicate that, but the latest commit 43aa262 should at least make it fail gracefully and not stop the scraping process.

I'll leave this open for now - let me know if you figure a way to consistently replicate that or if it fails with a specific book in particular.

@leoncvlt leoncvlt mentioned this issue Apr 3, 2020
@mikan01
Copy link
Author

mikan01 commented Apr 3, 2020

It's still failing. :\

I am able to download few books 1 or 2 at a time then process gets stopped with this error, then I have rerun the command to scrape more books.

Traceback (most recent call last):
File "C:\Users\Fang Yuan\Downloads\blinkist-scraper-master\scraper.py", line 229, in scrape_book_audio
audio_request_json = audio_request.json();
File "C:\Python38\lib\site-packages\requests\models.py", line 888, in json
return complexjson.loads(
File "C:\Python38\lib\json_init_.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python38\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 66, in
audio_files = scraper.scrape_book_audio(driver, book_json, args.language)
File "C:\Users\Fang Yuan\Downloads\blinkist-scraper-master\scraper.py", line 239, in scrape_book_audio
print(f'[!] Received malformed json data: {audio_request_json.text}')
UnboundLocalError: local variable 'audio_request_json' referenced before assignment

@Wunderharke
Copy link

It's still failing. :\

I am able to download few books 1 or 2 at a time then process gets stopped with this error, then I have rerun the command to scrap more books.

Traceback (most recent call last):
File "C:\Users\Fang Yuan\Downloads\blinkist-scraper-master\scraper.py", line 229, in scrape_book_audio
audio_request_json = audio_request.json();
File "C:\Python38\lib\site-packages\requests\models.py", line 888, in json
return complexjson.loads(
File "C:\Python38\lib\json__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python38\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 66, in
audio_files = scraper.scrape_book_audio(driver, book_json, args.language)
File "C:\Users\Fang Yuan\Downloads\blinkist-scraper-master\scraper.py", line 239, in scrape_book_audio
print(f'[!] Received malformed json data: {audio_request_json.text}')
UnboundLocalError: local variable 'audio_request_json' referenced before assignment

I am getting the same error when scraping the second book on a new clone on ca0d913.

@Wunderharke
Copy link

Wunderharke commented Apr 3, 2020

I might found the cause:

The error occurs after accepting the cookies inside the ChromeDriver window.
It seems there is some interference, maybe with some json data on side-loaded sites, just guessing ...

When not interacting with the Chrome window, the program seems to work like expected.

@leoncvlt
Copy link
Owner

leoncvlt commented Apr 3, 2020

My bad, latest commit 426d5bd should fix the handling of the exception. Again, it will not fix the bug but at least it should handle it without stopping the program and provide some more information about what's failing.

@Wunderharke Interesting! I never touch the Chrome window while scraping anyway, since it's all automated - just let it do its job. @mikan01 can you confirm if that makes it better for you too?

@mikan01
Copy link
Author

mikan01 commented Apr 3, 2020

My bad, latest commit 426d5bd should fix the handling of the exception. Again, it will not fix the bug but at least it should handle it without stopping the program and provide some more information about what's failing.

@Wunderharke Interesting! I never touch the Chrome window while scraping anyway, since it's all automated - just let it do its job. @mikan01 can you confirm if that makes it better for you too?

Thank you, now the problem seems to be fixed. :)

@rocketinventor
Copy link
Contributor

@mikan01,
If this issue has been resolved would you please consider closing it?

Thanks!

leoncvlt pushed a commit that referenced this issue May 8, 2021
New Captcha Behaviour and dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants