Files

Other topics

Remarks:

The r variable in the examples contains the full binary data of whatever file you're sending.

Simple File Upload

url = 'http://your_url'
files = {'file': open('myfile.test', 'rb')}
r = requests.post(url, files=files)

File Upload w/ Manual Params

url = 'http://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 = 'http://httpbin.org/post'
files = {'file': ('report.csv', 'some,data,to,send\nanother,row,to,send\n')}
r = requests.post(url, files=files)
r.text

Parameters:

ParametersFunction
fileJSON List of paths to the files.
content_typeMIME Types
headersHTTP Headers

Contributors

Topic Id: 5929

Example Ids: 20804,20805,20806

This site is not affiliated with any of the contributors.