Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

HTTP 502 error causes JSONDecodeError #101

Open
tanyanghan opened this issue Feb 24, 2021 · 0 comments
Open

HTTP 502 error causes JSONDecodeError #101

tanyanghan opened this issue Feb 24, 2021 · 0 comments

Comments

@tanyanghan
Copy link

tanyanghan commented Feb 24, 2021

This happened in the middle of a script that has been running for quite a while now.
It should raise a more appropriate Exception or at least the response.status_code so that the module user can determine it's a 502 bad gateway and retry after a small delay.

   DEBUG 2021-02-24 06:16:54,383 : Starting new HTTPS connection (1): api.imgur.com:443
   DEBUG 2021-02-24 06:17:55,455 : https://api.imgur.com:443 "POST /3/upload HTTP/1.1" 502 9
   ERROR 2021-02-24 06:17:55,464 : JSON decoding of response failed.
   ERROR 2021-02-24 06:17:55,465 : None
   ERROR 2021-02-24 06:17:55,466 : ImgurClientError: ImgurClientError
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.9/site-packages/imgurpython/client.py", line 156, in make_request
    response_data = response.json()
  File "/home/pi/.local/lib/python3.9/site-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/home/pi/.pyenv/versions/3.9.2/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/home/pi/.pyenv/versions/3.9.2/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/pi/.pyenv/versions/3.9.2/lib/python3.9/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 "/home/pi/Code/dealer/combinations.py", line 231, in <module>
    generate_upload_trios()
  File "/home/pi/Code/dealer/combinations.py", line 205, in generate_upload_trios
    image_upload(path, filename, album_name, album_id, hand_name)
  File "/home/pi/Code/dealer/combinations.py", line 82, in image_upload
    result = client.upload_from_path(path, config, anon=False)
  File "/home/pi/.local/lib/python3.9/site-packages/imgurpython/client.py", line 596, in upload_from_path
    return self.make_request('POST', 'upload', data, anon)
  File "/home/pi/.local/lib/python3.9/site-packages/imgurpython/client.py", line 158, in make_request
    raise ImgurClientError('JSON decoding of response failed.')
imgurpython.helpers.error.ImgurClientError: JSON decoding of response failed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant