import requests

headers = {'Content-type': 'content_type_value'}
r = requests.get(url, headers=headers)
Answer from Vikas Ojha on Stack Overflow
🌐
ProxiesAPI
proxiesapi.com › articles › setting-the-content-type-header-for-python-requests
Setting the Content-Type Header for Python Requests | ProxiesAPI
import requests import json data = {'key1': 'value1', 'key2': 'value2'} headers = {'Content-Type': 'application/json'} response = requests.post(url, headers=headers, data=json.dumps(data))
Discussions

Code Snippet > Python - Requests > Wrong 'Content-Type'
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. ... Create new (working) multipart POST request. More on github.com
🌐 github.com
0
April 26, 2024
requests with multiparts using data and files doesn't have content-type in data part
When issuing a requests.post request("POST"...) with data and files, the content-type for the data doesn't get set. Environment Windows 11 Python 3.10.7 Trying to debug why a Postman ... More on github.com
🌐 github.com
4
July 19, 2023
What's the correct `content-type` when editing posts?
Hey folks, can I use application/json as Content-Type when updating a post via the API? The docs say I can, but I am starting to think I cannot… I constantly get ["BAD CSRF"] and I have no clue what that means. If I need to use multipart/form-data do you folks have any pointers on how I build ... More on meta.discourse.org
🌐 meta.discourse.org
1
0
August 10, 2021
Can requests.post calculate the Content-Length header when passed a dictionary of strings?
Does it help if you remove your 'Accept-Encoding' header, or change it to this? headers={'Accept-Encoding': 'identity'} More on reddit.com
🌐 r/learnpython
2
3
August 8, 2022
People also ask

Does the Python requests library support asynchronous POST requests?

Unfortunately, the requests library does not support asynchronous requests. However, the httpx library is an alternative that provides async capabilities, making it suitable for applications requiring concurrency. See our guide to Python httpx for details.

🌐
scrapfly.io
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method - Scrapfly Blog
How can I include custom headers in using Python requests?

Pass headers as a dictionary using the headers parameter. Note that requests automatically generates some headers like User-Agent, Content-Length and Content-Type, so be cautious when overriding them.

🌐
scrapfly.io
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method - Scrapfly Blog
What is the difference between data and json parameters in Python requests?

data is for form-encoded (default) or raw data (when Content-Type header is overriden). While json is specifically for JSON format data and automatically sets Content-Type to application/json.

🌐
scrapfly.io
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method - Scrapfly Blog
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.33.0 documentation
Requests’ simple API means that all forms of HTTP request are as obvious. For example, this is how you make an HTTP POST request:
🌐
ScrapeOps
scrapeops.io › home › python web scraping playbook › python requests post requests
Python Requests - How to Send POST Requests | ScrapeOps
April 12, 2023 - We simply just need to add the ... the response print(response.json()) The requests library will automatically encode the data as JSON and set the Content-Type header to application/json....
🌐
ScrapingDog
scrapingdog.com › blog › send-post-python-requests
How To Send A Post Requests in Python?
October 2, 2024 - Python tutorial on sending POST requests with requests. Covers JSON bodies (use json= + headers), form-encoded logins, and file uploads (files= auto-sets content type).
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-requests-post-request-with-headers-and-body
Python requests - POST request with headers and body - GeeksforGeeks
July 23, 2025 - Python · import requests import json url = "https://httpbin.org/post" headers = {"Content-Type": "application/json; charset=utf-8"} data = { "id": 1001, "name": "geek", "passion": "coding", } response = requests.post(url, headers=headers, ...
🌐
ReqBin
reqbin.com › code › python › m2g4va4a › python-requests-post-json-example
How do I post JSON using the Python Requests Library?
The json= parameter takes a dictionary and automatically converts it to a JSON string. The Request Library automatically adds the Content-Type: application/json header to your request when using the json= parameter.
🌐
Scrapfly
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method - Scrapfly Blog
November 5, 2024 - Form data sends data with Content-Type header application/x-www-form-urlencoded and URL-encodes data in a key-value format. Let's see an example of how to POST Form Data with Python Requests to better understand this format:
🌐
Leapcell
leapcell.io › blog › how-to-use-python-requests-for-post-requests
How to Use Python `requests` for POST Requests | Leapcell
July 25, 2025 - You can install it using pip: ... To send a POST request, use the requests.post() method, specifying the target URL and the data to be sent. By default, the data is sent with a Content-Type header of application/x-www-form-urlencoded.
🌐
ScrapingBee
scrapingbee.com › blog › how-to-send-post-python-requests
How to send a POST with Python Requests? | ScrapingBee
January 11, 2026 - The main difference is what kind of data you're sending: Form data → use data=.... This sends application/x-www-form-urlencoded (similar to a regular web form). JSON data → use json=.... Requests sets Content-Type: application/json for you ...
🌐
ProxiesAPI
proxiesapi.com › articles › setting-the-content-type-header-for-post-requests-with-the-python-requests-library
Setting the Content-Type Header for POST Requests with the Python Requests Library | ProxiesAPI
February 1, 2024 - import requests url = 'https://api.example.com/users' data = {'name': 'John Doe'} headers = {'Content-Type': 'application/json'} response = requests.post(url, headers=headers, json=data) ... Content-Type.
🌐
Scrapfly
scrapfly.io › blog › posts › python-requests-headers-guide
Guide to Python Requests Headers - Scrapfly Blog
October 29, 2024 - For POST requests, headers are ... Content-Type: Indicates the data format, such as application/json for JSON data, application/x-www-form-urlencoded for form submissions, or multipart/form-data for files....
🌐
AnyIP
anyip.io › blog › python-requests-post
How to make a POST with the Python Requests module?
Python Copy · import requests url = "https://httpbin.org/post" my_data = {"john": "doe"} response = requests.post(url, json=my_data) print(response.json()) The output should look like this: Bash Copy · {'args': {}, 'data': '{"john": "doe"}', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': '15', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.32.3', 'X-Amzn-Trace-Id': 'Root=1-66eafda9-03c9f45c5ba30bca01a205c5'}, 'json': {'john': 'doe'}, 'origin': 'IP-CENSORED', 'url': 'https://httpbin.org/post'} We will cover the json parameter's specifics.
🌐
GitHub
github.com › postmanlabs › postman-app-support › issues › 12817
Code Snippet > Python - Requests > Wrong 'Content-Type' · Issue #12817 · postmanlabs/postman-app-support
April 26, 2024 - 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)
Author   JanHusarcik
🌐
ReqBin
reqbin.com › code › python › ighnykth › python-requests-post-example
How do I send a POST request using Python Requests Library?
To send a POST request using the ... data with the data= parameter. You must also specify the data type in the body of the POST message using the Content-Type request header so that the server can correctly receive and process ...
🌐
ReqBin
reqbin.com › req › python › xpcr0cv3 › client-request-with-content-type-header
Python | How do I send a Client request with a Content-Type header?
December 20, 2022 - POST /echo/post/json HTTP/1.1 Host: reqbin.com Accept: application/json Content-Type: application/json Content-Length: 16 {"key": "value"} Server response to our Request with Content-Type Header: ... Convert your Client Request Content Type Header request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the Python code generator.
🌐
GitHub
github.com › psf › requests › issues › 6484
requests with multiparts using data and files doesn't have content-type in data part · Issue #6484 · psf/requests
July 19, 2023 - Postman: ----------------------------166390214727573301705303 Content-Disposition: form-data; name="documents_input" Content-Type: application/json · {"requests":[{"request_id":"f631ffc..... ----------------------------166390214727573301705303 Content-Disposition: form-data; name="files"; filename="removed.pdf" Content-Type: application/pdf · Python: --285101b8d40c60d675e8f54e937ceb3e Content-Disposition: form-data; name="documents_input"
Author   Cratig
🌐
Linux Hint
linuxhint.com › python-post-request-set-content-type
Python Post Request Set Content-Type
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Discourse
meta.discourse.org › dev
What's the correct `content-type` when editing posts? - Dev - Discourse Meta
August 10, 2021 - Hey folks, can I use application/json as Content-Type when updating a post via the API? The docs say I can, but I am starting to think I cannot… I constantly get ["BAD CSRF"] and I have no clue what that means. If I need to use multipart/form-data do you folks have any pointers on how I build my put request?