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 exception when uploading images #23

Closed
sergioteula opened this issue Jan 28, 2020 · 9 comments
Closed

JSON exception when uploading images #23

sergioteula opened this issue Jan 28, 2020 · 9 comments

Comments

@sergioteula
Copy link

Hello, from a few days ago I'm getting below error when trying to upload images to Telegraph. It has been working like a charm for almos half a year now, so I don't know why now I'm having this issue. I'm not sure if it's a server side issue or something else. Any idea? Thanks in advance!

url = telegraph.upload.upload_file(image_name)
File "/telegraph/upload.py", line 18, in upload_file
files=files
File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/models.py", line 850, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/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)

@AyraHikari
Copy link

It's look like server issue, i had this error too, but sometimes it got works.
Maybe server is return something that json cannot parse

@javad94
Copy link

javad94 commented Jan 29, 2020

@AyraHikari Is there a way to see the server error without modifying this package codes?

@AyraHikari
Copy link

@AyraHikari Is there a way to see the server error without modifying this package codes?

You can upload manual using requests post, see #3
Don't forget to change .json() to .text to check why server is not return a valid json

@javad94
Copy link

javad94 commented Jan 31, 2020

@AyraHikari Is there a way to see the server error without modifying this package codes?

You can upload manual using requests post, see #3
Don't forget to change .json() to .text to check why server is not return a valid json

Thanks.

@sergioteula
Copy link
Author

The issue has disappeared, seems like it was a server side error.

@annihilatorrrr
Copy link

{"error":"No files passed"}
while we are passing a file:

import requests
with open('./testimage.jpg', 'rb') as f:
print(
requests.post(
'http://telegra.ph/upload',
files={'file': ('file', f, 'image/png')} # image/gif, image/jpeg, image/jpg, image/png, video/mp4
).text
)

@python273
Copy link
Owner

@annihilatorrrr try to use telegraph.upload_file('./testimage.jpg')

@annihilatorrrr
Copy link

Oke leme try

@annihilatorrrr
Copy link

@annihilatorrrr try to use telegraph.upload_file('./testimage.jpg')

Thanks dude it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants