Posting image to thumbor using requests package

By | May 13, 2016

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

import requests

# local file
with open('image.jpg', 'rb') as file:
    resp ='http://localhost:8888/image',
    url = resp.headers['Location']

# remote file
remote_resp = requests.get(image_url, stream=True)
resp ='http://localhost:8888/image', data=remote_resp.content)
url = resp.headers['Location']


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.