Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mime type for Requests post file

How do I set the mime type for files (for one file, not for the form) uploaded with Python Requests?

import requests
requests.post('http://test.com/upload', files={'data':'123'})
like image 691
Ruediger Jungbeck Avatar asked Jan 28 '14 07:01

Ruediger Jungbeck


1 Answers

You can use tuples and lists to pass additional options for posted files. http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file

{file_field: (name, content, content_type, additional_file_headers)}

So

import requests
requests.post('http://test.com/upload', files={'data': ('readme.txt', 'Readme file content or pointer', 'text/plain')})
like image 89
Alexander Klimenko Avatar answered Oct 20 '22 19:10

Alexander Klimenko