Reputation:
Is it possible to send a multipart/form-data with python requests without sending a file?
My requests header should look like this:
--3eeaadbfda0441b8be821bbed2962e4d
Content-Disposition: form-data; name="value";
content
--3eeaadbfda0441b8be821bbed2962e4d--
But actually it looks like this:
--3eeaadbfda0441b8be821bbed2962e4d
Content-Disposition: form-data; name="file"; filename="file"
Content-Type: text/plain
content
--3eeaadbfda0441b8be821bbed2962e4d--
I'm using this function:
response = requests.post('url', data, files=('file', 'file'))
Upvotes: 4
Views: 1658
Reputation: 10135
Yes, you could, just pass dictionary with tuples as values to post method. When you specify files
parameter to this method requests
add multipart/form-data
header. But you free to pass dictionary with tuples as files
:
url = 'http://httpbin.org/post'
files = {'file': (None, 'some,data,to,send\nanother,row,to,send\n')}
r = requests.post(url, files=files)
http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
Upvotes: 4