Posting image to thumbor using requests package
Seems like there are not many code sample there, and the requests documentation was giving the wrong hint to use files={‘file’: open(‘image.jpg’)} which you will end up getting 415 response code. I think I will just share my working sample code here to save someone’s time
1 2 3 4 5 6 7 8 9 10 11 |
import requests # local file with open('image.jpg', 'rb') as file: resp = requests.post('http://localhost:8888/image', data=file.read()) url = resp.headers['Location'] # remote file remote_resp = requests.get(image_url, stream=True) resp = requests.post('http://localhost:8888/image', data=remote_resp.content) url = resp.headers['Location'] |