Search code examples
pythonfilepython-requestsmultipartform-datacontent-type

How to send a 'multipart/form-data' with requests, without files in Python


I want to send a 'multipart/form-data' dictionary data without files

headers = {'key':'value', 'Content-Type':'multipart/form-data'}
data = {'api_key':'api_value', ... }

response = request.post('API_URL', headers=headers, data=data)

but API response is:

FileUploadException: the request was rejected because no multipart boundary was found

so I changed 'multipart/form-data' -> 'multipart/form-data; boundary=____sample' This code also didn't work. It didn't recognize the parameters.

How can I send 'multipart/form-data' requests without files?


Solution

  • I'm not entirely sure how python works with requests. You can try this accepted answers or any which is suitable

    python requests - POST Multipart/form-data without filename in HTTP request