python273 / telegraph

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

Some problem with requests.post when I want to send a photo #16

Closed govorushagreat closed 6 years ago

govorushagreat commented 6 years ago

import requests

with open('C:/Users/Admin/Desktop/photo_2018-08-13_16-31-15.jpg', 'rb') as f: print( requests.post( 'http://telegra.ph/upload', files={'file': ('file', f, 'image/jpg')} # image/gif, image/jpeg, image/jpg, image/png, video/mp4 ).json() )

Result: {'error': 'No files passed'}

Аny ideas?

python273 commented 6 years ago

Can you try to use upload_file function?

print(telegraph.upload_file('C:/Users/Admin/Desktop/photo_2018-08-13_16-31-15.jpg'))
govorushagreat commented 6 years ago

I get the "'Telegraph' object has no attribute 'upload_file'", but the library is correctly installed in the environment

govorushagreat commented 6 years ago

The most interesting point is that a week ago there were no problems

govorushagreat commented 6 years ago

Just a week ago this code was working: photo = open(path, 'rb') new_path = requests.post( 'http://telegra.ph/upload', files={'file': ('file', photo, 'image/jpeg')}).json()[0]['src'] content += "".format(new_path)

python273 commented 6 years ago

Replace http with https

govorushagreat commented 6 years ago

Did not help

python273 commented 6 years ago

Try to install the module via

pip install https://github.com/python273/telegraph/archive/master.zip

and use

print(telegraph.upload_file('C:/Users/Admin/Desktop/photo_2018-08-13_16-31-15.jpg'))