python-requests

Files

Parameters#

Parameters Function
file JSON List of paths to the files.
content_type MIME Types
headers HTTP Headers
## Remarks#
The r variable in the examples contains the full binary data of whatever file you’re sending.
## Simple File Upload
url = 'https://your_url'
files = {'file': open('myfile.test', 'rb')}
r = requests.post(url, files=files)

File Upload w/ Manual Params

url = 'https://httpbin.org/post'
files = {'file': ('report.xls', open('report.xls', 'rb'), 'application/vnd.ms-excel', {'Expires': '0'})}
r = requests.post(url, files=files)

Sending Strings as FIles

url = 'https://httpbin.org/post'
files = {'file': ('report.csv', 'some,data,to,send\nanother,row,to,send\n')}
r = requests.post(url, files=files)
r.text

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow