Imgur / imgurpython

Official Imgur python client library (deprecated)
MIT License
544 stars 116 forks source link

Uploading an ~35mb gif throws JSONDecodeError #73

Open rj93 opened 8 years ago

rj93 commented 8 years ago

So I am trying to uplaod a gif using the upload_from_path function. This works for small gifs, but when I try to upload a larger one I get the following error:

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\imgurpython\client.py", line 156, in make_request
    response_data = response.json()
  File "C:\Program Files\Anaconda3\lib\site-packages\requests\models.py", line 808, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Program Files\Anaconda3\lib\json\__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Anaconda3\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Anaconda3\lib\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\richard\Desktop\imgur_test.py", line 62, in <module>
    response = upload(file_name)
  File "C:\Users\richard\Desktop\imgur_test.py", line 44, in upload
    return imgur.upload_from_path(file_name)
  File "C:\Program Files\Anaconda3\lib\site-packages\imgurpython\client.py", line 596, in upload_from_path
    return self.make_request('POST', 'upload', data, anon)
  File "C:\Program Files\Anaconda3\lib\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.
[Finished in 37.0s with exit code 1]

Reproduction code:

import urllib.request, shutil
from imgurpython import ImgurClient

imgur_client_id = 'client_id'
imgur_client_secret = 'client_secret'
imgur = ImgurClient(imgur_client_id, imgur_client_id)

def download_file(url, file_name):
    with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
        shutil.copyfileobj(response, out_file)

def upload(file_name):
    return imgur.upload_from_path(file_name)

if __name__ == '__main__':
    url = 'http://i.imgur.com/h3qtAz9.gif'
    file_name = 'test.gif'
    print("starting download")
    download_file(url, file_name)
    print("download complete\nstarting upload")
    response = upload(file_name)
    print("upload complete")