Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Snippet > Python - Requests > Wrong 'Content-Type' #12817

Open
1 task done
JanHusarcik opened this issue Apr 26, 2024 · 0 comments
Open
1 task done

Code Snippet > Python - Requests > Wrong 'Content-Type' #12817

JanHusarcik opened this issue Apr 26, 2024 · 0 comments

Comments

@JanHusarcik
Copy link

Is there an existing issue for this?

  • 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

  1. Create new (working) multipart POST request.
  2. Generate code snippet for Python - Requests.
  3. Run the code using e.g. python 3.10.10 and requests 2.31.0
  4. request will fail (likely with error 500)
  5. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant