I often forget it, so make a note.
import requests
def send():
image = open('/path/to/file', 'rb')
files = {'param_name': ('filename.jpg', image, 'image/jpeg')}
data = {'another_key': 'another_value'}
r = requests.post(URL, files=files, data=data)
print r.text
You can specify the file name and content-type by setting the value of the contents of files to tuple.
Reference: https://github.com/kennethreitz/requests/issues/1495#issuecomment-21581939
Recommended Posts