JSONDecodeError
Hello, thanks for the great tool! 🙂 Just recently it stopped working, I tried upgrading to version 2.4.0, but maybe LC API has changed?
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/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 "/usr/local/bin/leetcode-export", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/site-packages/leetcode_export/__main__.py", line 158, in main
if not leetcode.set_cookies(cookies):
File "/usr/local/lib/python3.8/site-packages/leetcode_export/leetcode.py", line 94, in set_cookies
if self.is_user_logged():
File "/usr/local/lib/python3.8/site-packages/leetcode_export/leetcode.py", line 111, in is_user_logged
if "detail" not in get_request.json():
File "/usr/lib/python3.8/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Hi @garncarz, thank you for using leetcode-export!
I'm not able to reproduce the issue you're facing. Could you please check that you're pasting the leetcode cookies correctly?
You can get them from the network tab in the dev tools. Everything under Cookie (the red box in the following screenshot) has to be supplied to leetcode-export.
If that doesn't work, could you share the debug logs? You can get them by running leetcode-export with the -vv flag. Make sure to redact any sensitive information if there are.
Thanks for such quick reply!
In the previous versions, I had to manually pick just csrftoken and LEETCODE_SESSION from cookies, otherwise it erred. Now it seems to work for the whole cookie set.
Maybe this error is caused because it gets HTML instead of JSON?
2024-03-31 23:15:41,463 [DEBUG] connectionpool.py:971 - Starting new HTTPS connection (1): leetcode.com:443
2024-03-31 23:15:41,555 [DEBUG] connectionpool.py:452 - https://leetcode.com:443 "GET /api/submissions/?offset=0&limit=1 HTTP/1.1" 403 None
2024-03-31 23:15:41,556 [DEBUG] leetcode.py:109 - <!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title>
Interesting, https://leetcode.com/api/submissions/?offset=0&limit=1 gives me JSON when accessing that in Chrome.
Looks like it's a rate limit or an attempt to mess with tools like leetcode-export. I'll make some changes to fix that, retrying that HTTP request should work.
I also encoutered the same problem, the returned body seems like the Cloudflare Captcha.
<!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta name="robots" content="noindex,nofollow"><meta name="viewport" content="width=device-width,initial-scale=1">
I changed my IP address using a VPN, finally the script works fine.
I also encoutered the same problem, the returned body seems like the Cloudflare Captcha.
<!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta name="robots" content="noindex,nofollow"><meta name="viewport" content="width=device-width,initial-scale=1">I changed my IP address using a VPN, finally the script works fine.
@WangYihang Thank you for sharing!
When I'll have time I'll update the logic to retry the request a couple of times in case it's unsuccessful