Inconsistent behavior when converting cURL multipart/form-data request to Python requests
Author: COCONUTwwaterCreated Apr 21, 2025Updated Sep 2, 2025
Labelsincorrect output
Issue Description
When converting a cURL request with multipart/form-data to Python requests, the request fails to match the original cURL behavior, while Postman's conversion works correctly.
Steps to Reproduce
- Original cURL request:
curl 'https://example.com/' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundaryaaaaa' \
--data-raw $'------WebKitFormBoundaryaaaaa\r\nContent-Disposition: form-data; name="time_type"\r\n\r\nBILL_TIME\r\n------WebKitFormBoundaryaaaaa\r\nContent-Disposition: form-data; name="start_time"\r\n\r\n1735660800\r\n------WebKitFormBoundaryaaaaa\r\nContent-Disposition: form-data; name="end_time"\r\n\r\n1745164799\r\n------WebKitFormBoundaryaaaaa--\r\n'- Python requests attempt (not working):
import requests
headers = {
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryaaaaa',
}
files = {
'time_type': (None, 'BILL_TIME'),
'start_time': (None, '1735660800'),
'end_time': (None, '1745164799'),
}
response = requests.post('https://example.com/', headers=headers, files=files)- Postman's conversion (working):
import requests
url = "https://example.com/"
payload = {
'time_type': 'BILL_TIME',
'start_time': '1735660800',
'end_time': '1745164799'
}
files = []
headers = {
'accept': 'application/json, text/plain, */*'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)Expected Behavior
The Python requests library should generate the same multipart/form-data request as the original cURL command.
Actual Behavior
The Python requests library generates a different multipart/form-data structure, causing the request to fail.
Source: curlconverter/curlconverter