Reputation: 151
Im making a multipart POST using the python package requests. Im using xlrd to change some values in an Excel file save it then send that up in a multipart POST. This working fine when I run it locally on my mac but when I put the code on a remote machine and make the same request the body content type is blank where as locally the body content type is application/vnd.ms-excel. So my question is, is there a way enforce the content type using python requests so that in this case the body content type is application/vnd.ms-excel. Sorry cant post up any code as I don't have it on this machine.
Upvotes: 2
Views: 3412
Reputation: 15518
The files
parameter accepts a dictionary of keys to tuples, with the following form:
files = {'name': (<filename>, <file object>, <content type>, <per-part headers>)}
In your specific case, you could write this:
files = {'file': ('filename.xls', open('filename.xls'), 'application/vnd.ms-excel', {})}
That should work fine.
Upvotes: 10
Reputation: 477
I believe you can use the headers parameter, e.g
requests.post(url, data=my_data, headers={"Content-type": "application/vnd.ms-excel"})
Upvotes: 0