Serene-Arc / bulk-downloader-for-reddit

Downloads and archives content from reddit
https://pypi.org/project/bdfr
GNU General Public License v3.0
2.28k stars 211 forks source link

[BUG] json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #774

Open lemixtape opened 1 year ago

lemixtape commented 1 year ago

I am reporting a bug.

I am running the latest version of BDfR

I have read the Opening an issue

Description

When I run this command:

bdfr archive /home/osint/Downloads/Reddit/php --authenticate --subreddit php --sort new --folder-scheme ''

I get the following error that stops the execution of the program before it collects anything:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 971, in json return complexjson.loads(self.text, **kwargs) File "/usr/lib/python3.10/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.10/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/bdfr", line 8, in sys.exit(cli()) File "/home/osint/.local/lib/python3.10/site-packages/click/core.py", line 1130, in call return self.main(args, kwargs) File "/home/osint/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/home/osint/.local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/osint/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/osint/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke return __callback(args, *kwargs) File "/home/osint/.local/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), args, **kwargs) File "/home/osint/.local/lib/python3.10/site-packages/bdfr/main.py", line 138, in cli_archive reddit_archiver = Archiver(config, [stream]) File "/home/osint/.local/lib/python3.10/site-packages/bdfr/archiver.py", line 30, in init super(Archiver, self).init(args, logging_handlers) File "/home/osint/.local/lib/python3.10/site-packages/bdfr/connector.py", line 63, in init self._setup_internal_objects() File "/home/osint/.local/lib/python3.10/site-packages/bdfr/connector.py", line 80, in _setup_internal_objects self.create_reddit_instance() File "/home/osint/.local/lib/python3.10/site-packages/bdfr/connector.py", line 139, in create_reddit_instance oauth2_authenticator = OAuth2Authenticator( File "/home/osint/.local/lib/python3.10/site-packages/bdfr/oauth2.py", line 21, in init self._check_scopes(wanted_scopes) File "/home/osint/.local/lib/python3.10/site-packages/bdfr/oauth2.py", line 31, in _check_scopes known_scopes = [scope for scope, data in response.json().items()] File "/usr/local/lib/python3.10/dist-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)

I am running Python 3.10 in Ubuntu 22.04 in Virtual Box. My host is Windows 11.

If I remove the --authenticate from the command, it runs without any issue. I am unsure as to what logs I could send you.

Serene-Arc commented 1 year ago

Please send the logs. Logs are required for any bug report, as described in the guide for opening a bug report. The BDFR generates these logs every run. The guide that you should have read describes the location of the logs. Please supply them or this issue will be closed.

giuliano108 commented 1 year ago

In my case this happens when the Reddit API returns a 503...

Tested by adding raise_for_status:

*** venv/lib/python3.9/site-packages/bdfr/oauth2.py     2023-02-21 19:14:13.123957700 +0000
--- /home/giuliano/temp/bulk-downloader-for-reddit/bdfr/oauth2.py       2023-02-21 19:17:59.773957700 +0000
***************
*** 28,34 ****
          response = requests.get(
              "https://www.reddit.com/api/v1/scopes.json", headers={"User-Agent": "fetch-scopes test"}
          )
-         response.raise_for_status()
          known_scopes = [scope for scope, data in response.json().items()]
          known_scopes.append("*")
          for scope in wanted_scopes:
--- 28,33 ----

Before:

requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)                         

After:

requests.exceptions.HTTPError: 503 Server Error: Service Unavailable for url: https://www.reddit.com/api/v1/scopes.json
Serene-Arc commented 1 year ago

Without logs, there's nothing anyone can do to investigate this issue.