In my request, I have an array with string values and numbers. Here is a simple example:
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
m = MultipartEncoder(
fields={'field0': 'value', 'field1': ['Test1', 'test2'],
'field2': ('filename', 'test', 'text/plain')})
r = requests.post('http://httpbin.org/post', data=m, headers={'Content-Type': m.content_type})
print(r.text)
It woks but reqest is invalid. Here is response:
{
"args": {},
"data": "",
"files": {
"field1": "test2",
"field2": "test"
},
"form": {
"field0": "value"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "378",
"Content-Type": "multipart/form-data; boundary=99e888bfc6254e4b8a428f9f234a7be0",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.22.0",
"X-Bluecoat-Via": "85fb7b65b90c79fc"
},
"json": null,
"url": "https://httpbin.org/post"
}
I am unsing:
- requests_toolbelt v.0.9.1
- requests v.2.22.0