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'))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With