postman-app-support
postman-app-support copied to clipboard
Code Snippet > Python - Requests > Wrong 'Content-Type'
trafficstars
Is there an existing issue for this?
- [X] I have searched the tracker for existing similar issues and I know that duplicates will be closed
Describe the Issue
Hi team,
if I generate a code snippet for Python - Requests for a multipart POST request, a code such as this is generated:
import requests
url = "https://example.com"
payload = {'foob': 'bar'}
files=[
('file',('file.html','rb'),'text/html'))
]
headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
note the 'Content-Type' value. However, Python's Request module need to generate the 'Content-Type' itself, including the boundary.
See https://stackoverflow.com/a/12385661 for details.
Regards, Jano
Steps To Reproduce
- Create new (working) multipart POST request.
- Generate code snippet for Python - Requests.
- Run the code using e.g. python 3.10.10 and requests 2.31.0
- request will fail (likely with error 500)
- review the python's request headers (you can include
print(response.request.headers)on the last line to dump request's headers)
Screenshots or Videos
No response
Operating System
Windows
Postman Version
10.24.24
Postman Platform
Postman App
User Account Type
Signed In User
Additional Context?
No response