Starting with Requests version 2.4.2, you can use the json= parameter (which takes a dictionary) instead of data= (which takes a string) in the call:
Copy>>> import requests
>>> r = requests.post('http://httpbin.org/post', json={"key": "value"})
>>> r.status_code
200
>>> r.json()
{'args': {},
'data': '{"key": "value"}',
'files': {},
'form': {},
'headers': {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'close',
'Content-Length': '16',
'Content-Type': 'application/json',
'Host': 'httpbin.org',
'User-Agent': 'python-requests/2.4.3 CPython/3.4.0',
'X-Request-Id': 'xx-xx-xx'},
'json': {'key': 'value'},
'origin': 'x.x.x.x',
'url': 'http://httpbin.org/post'}
Answer from Zeyang Lin on Stack OverflowReqBin
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. In this Python Requests POST JSON example, we send a JSON data string to the ...
Delft Stack
delftstack.com › home › howto › python › post json data with requests python
How to POST JSON Data With requests in Python | Delft Stack
March 4, 2025 - The simplest way to post JSON data ... is by using the json parameter in the post method. This method automatically serializes your Python dictionary into a JSON string, making it effortless to send data to the server. ... import requests url = "https://api.example.com/data" data = { "name": "John Doe", "email": "john.doe@example.com" } response = requests.post(url, ...
How can I POST JSON data with Python's Requests library? - Stack Overflow
I need to POST JSON content from a client to a server. I'm using Python 2.7.1 and simplejson. The client is using Requests. The server is CherryPy. I can GET hard-coded JSON content from the server... More on stackoverflow.com
I don't really understand Requests python module
You might want to start with some basics on client-server communication before delving into networking/web-dev side of Python. As others have mentioned here, requests docs is a great place to learn about the library, but if you don't know what a 'POST' or 'GET' method is or what's a request header used for, the docs won't make much sense. There are plenty of free online resources which explains the above concepts. Listing some of them which I think should cover your case: https://www.freecodecamp.org/news/http-request-methods-explained/ https://doc.oroinc.com/api/http-methods/ https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON More on reddit.com
[Python] How to parse JSon response from a post request (Requests)
If I run your code I get NameError on session, maybe you need to define that for it to work? More on reddit.com
APIs: Params= vs json= whats the difference?
Maybe it's a good idea to study the basics of HTTP methods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods A GET request has no body, so the only (practical) way of delivering data with it is through its url, so GET hostname/api/some_object/?name='test' The requestst library supports that via its params= parameter. So in this case you would do params={'name': 'test'}. Then methods like PUT and POST are meant to deliver data through their body, for which you would normally use the data= parameter. However to simplify delivering a Python structure (dict/list or some combination thereof) as a JSON encoded body, it supports that via its json= parameter. It then also sets the correct content-type header. More on reddit.com
Videos
00:31
How to POST JSON data with Python requests library #shorts - YouTube
03:43
How to POST JSON data with Python Requests? - YouTube
04:42
Sending JSON Data Using Python Requests - YouTube
02:41
Python Requests | JSON - YouTube
04:41
Python Requests: How To Send POST Requests - YouTube
14:00
How to Access Web APIs using Python Requests and JSON - YouTube
Stack Abuse
stackabuse.com › how-to-post-json-data-using-requests-library-in-python
How to POST JSON Data Using requests Library in Python
June 27, 2023 - In this article, we took a look at how to use the requests library to make a POST request with JSON data in Python.
Top answer 1 of 10
1809
Starting with Requests version 2.4.2, you can use the json= parameter (which takes a dictionary) instead of data= (which takes a string) in the call:
Copy>>> import requests
>>> r = requests.post('http://httpbin.org/post', json={"key": "value"})
>>> r.status_code
200
>>> r.json()
{'args': {},
'data': '{"key": "value"}',
'files': {},
'form': {},
'headers': {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'close',
'Content-Length': '16',
'Content-Type': 'application/json',
'Host': 'httpbin.org',
'User-Agent': 'python-requests/2.4.3 CPython/3.4.0',
'X-Request-Id': 'xx-xx-xx'},
'json': {'key': 'value'},
'origin': 'x.x.x.x',
'url': 'http://httpbin.org/post'}
2 of 10
561
It turns out I was missing the header information. The following works:
Copyimport requests
url = "http://localhost:8080"
data = {'sender': 'Alice', 'receiver': 'Bob', 'message': 'We did it!'}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)
Carmatec
carmatec.com › home › python requests post json: best practices & examples 2026
Python Requests POST JSON: Best Practices & Examples 2026
February 3, 2026 - python from requests.auth import HTTPBasicAuth r = requests.post(url, json=payload, auth=HTTPBasicAuth("user", "pass")) # or shorthand r = requests.post(url, json=payload, auth=("user", "pass")) python def get_access_token(): r = requests.post( "https://auth.example.com/token", data={"grant_type": "client_credentials", "client_id": "...", "client_secret": "..."} ) return r.json()["access_token"] token = get_access_token() r = requests.post(api_url, json=data, headers={"Authorization": f"Bearer {token}"})
W3Schools
w3schools.com › python › ref_requests_post.asp
Python Requests post Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... import requests url = 'https://www.w3schools.com/python/demopage.php' myobj = {'somekey': 'somevalue'} x = requests.post(url, json = myobj) print(x.text) Run Example »
Codegive
codegive.com › blog › requests_python_json_post.php
Mastering <code>requests</code> Python JSON POST (2026): Unleash Your API Communication Power Today!
March 24, 2026 - Example 5: Robust Error Handling for POST Requests5. Common Mistakes When Using requests python json post
Scrapfly
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method
April 18, 2026 - Discover how to use Python's requests library for POST requests, including JSON, form data, and file uploads, along with response handling tips.
Plain English
python.plainenglish.io › how-to-send-post-requests-with-json-data-using-python-requests-daaffa0a3335
How to Send POST Requests with JSON Data Using Python Requests? | Python in Plain English
April 25, 2025 - Python handles this beautifully with dictionaries and lists. import requests url = "https://httpbin.org/post" nested_data = { "user": { "name": "Alice", "contact": { "email": "alice@example.com", "phone": "123-456-7890" } }, "roles": ["admin", "editor"] } response = requests.post(url, json=nested_data) print(response.json()) # Echoed response
LoadForge
loadforge.com › directory › getting-started › json-posts
POSTing JSON data - Getting Started - LoadForge - LoadForge
Setup and Imports Start by importing necessary modules like time, json, and relevant locust classes. Define User Behavior Create a class (QuickstartUser) that extends the HttpUser class from Locust. This will define the behavior of a simulated user. Set Waiting Time Use wait_time to simulate the wait period between tasks. This example uses a randomized wait time of 3 to 5 seconds. Define the Task Within the user class, define a task named api_page. This task sends a POST request with the payload.
Datasciencebyexample
datasciencebyexample.com › 2023 › 03 › 12 › using-json-or-data-parameter-in-requests-post
Difference between `json` and `data` parameter of the HTTP POST Requests with JSON Data in Python using the Requests Library | DataScienceTribe
March 12, 2023 - In this example, we define a url variable that represents the endpoint where we want to send the POST request. We also define a payload variable that contains the JSON data we want to send. To send the POST request, we use the requests.post() method and pass the url and json parameters.
Codemia
codemia.io › knowledge-hub › path › how_to_post_json_data_with_python_requests
How to POST JSON data with Python Requests?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises