python273 / telegraph

Telegraph API wrapper | Telegra.ph
https://pypi.org/project/telegraph/
MIT License
287 stars 43 forks source link

JSON exception when uploading images #23

Closed sergioteula closed 4 years ago

sergioteula commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

AyraHikari commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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

annihilatorrrr commented 2 years ago

{"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 commented 2 years ago

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

annihilatorrrr commented 2 years ago

Oke leme try

annihilatorrrr commented 2 years ago

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

Thanks dude it worked