The reason you're getting JSON is because you're explicitly calling json.dumps to generate a JSON string. Just don't do that, and you won't get a JSON string. In other words, change your first line to this:

data = {'param1': 'value1', 'param2': 'value2'}

As the docs explain, if you pass a dict as the data value, it will be form-encoded, while if you pass a string, it will be sent as-is.


For example, in one terminal window:

$ nc -kl 8765

In another:

$ python3
>>> import requests
>>> d = {'spam': 20, 'eggs': 3}
>>> requests.post("http://localhost:8765", data=d)
^C
>>> import json
>>> j = json.dumps(d)
>>> requests.post("http://localhost:8765", data=j)
^C

In the first terminal, you'll see that the first request body is this (and Content-Type application/x-www-form-urlencoded):

spam=20&eggs=3

… while the second is this (and has no Content-Type):

{"spam": 20, "eggs": 3}
Answer from abarnert on Stack Overflow
Discussions

Urlencoded sending a JSON string
I have an API that has been set up on the server side and the unit side, I have the below code in python to communicate with the API. I am now writing this for the Arduino IDE. This code successfully communicates with the API to get the token. How is this code sending a JSON string ‘auth_info’ ... More on discuss.python.org
🌐 discuss.python.org
0
0
February 18, 2022
[Feature] Enhance Handling of x-www-form-urlencoded Data in HTTP Requests
Current Behavior: When making HTTP POST requests with form data using Playwright's request context, the payload data needs to be explicitly URL-encoded using methods like urllib.parse.urlencode. Th... More on github.com
🌐 github.com
2
September 27, 2023
Python : Trying to POST form using requests - Stack Overflow
I'm trying to login a website for some scraping using Python and requests library, I am trying the following (which doesn't work): import requests headers = {'User-Agent': 'Mozilla/5.0'} payload = {' More on stackoverflow.com
🌐 stackoverflow.com
PYTHON: requests.post() how to send request_body encoded as application/x-www-form-urlencoded - Stack Overflow
I'm doign an app with the Spotify API. My problem is I'm trying to get an access_token but It's not working. In the docs it says i need to send the body encoded as application/x-www-form-urlencoded... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How do I send form data with Python Requests?
Pass a dict via data. Requests encodes it as application/x-www-form-urlencoded. For files, combine data for fields with files for uploads.
🌐
scrapingbee.com
scrapingbee.com › blog › how-to-send-post-python-requests
How to send a POST with Python Requests? | ScrapingBee
What is the difference between data and json in Python Requests POST?
data sends form-encoded fields; json serializes your dict and sets Content-Type: application/json. Use data for web forms and json for APIs.
🌐
scrapingbee.com
scrapingbee.com › blog › how-to-send-post-python-requests
How to send a POST with Python Requests? | ScrapingBee
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.

🌐
scrapfly.io
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method
🌐
ScrapingBee
scrapingbee.com › blog › how-to-send-post-python-requests
How to send a POST with Python Requests? | ScrapingBee
January 11, 2026 - To send a POST request in Python, you typically use requests.post. 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).
🌐
Python.org
discuss.python.org › python help
Urlencoded sending a JSON string - Python Help - Discussions on Python.org
February 18, 2022 - I have an API that has been set up on the server side and the unit side, I have the below code in python to communicate with the API. I am now writing this for the Arduino IDE. This code successfully communicates with the API to get the token. How is this code sending a JSON string ‘auth_info’ while the header reads x-www-form-urlencoded.
🌐
FastAPI
fastapi.tiangolo.com › tutorial › request-forms
Form Data - FastAPI
Data from forms is normally encoded using the "media type" application/x-www-form-urlencoded. But when the form includes files, it is encoded as multipart/form-data. You'll read about handling files in the next chapter.
🌐
GitHub
github.com › microsoft › playwright-python › issues › 2088
[Feature] Enhance Handling of x-www-form-urlencoded Data in HTTP Requests · Issue #2088 · microsoft/playwright-python
September 27, 2023 - from playwright.sync_api import sync_playwright import urllib.parse payload = { "grant_type": "client_credentials", "client_id": "example-client-id", "client_secret": "example-secret", "scope": "example.scope" } with sync_playwright() as p: response = api_request_context.post(url, data=urllib.parse.urlencode(payload))
Author   dron4ik86
🌐
ScrapingDog
scrapingdog.com › blog › send-post-python-requests
How To Send A Post Requests in Python?
October 2, 2024 - Generally, the value of the content-type header is application/x-www-form-urlencoded while submitting a form. You can read this guide on how to scrape data behind authentication with Python for more details.
Find elsewhere
🌐
Scrapfly
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method
September 26, 2025 - application/x-www-form-urlencoded used in HTML form submissions, encoding data as URL-encoded key-value pairs. multipart/form-data designed for file uploads, supporting mixed content like binary files and text in a single request.
🌐
WebScraping.AI
webscraping.ai › faq › requests › how-do-i-handle-post-requests-with-url-encoded-data
How do I handle POST requests with URL-encoded data? | WebScraping.AI
async function submitForm(formData) { const url = 'https://example.com/api/submit'; // Convert object to URLSearchParams const params = new URLSearchParams(); Object.keys(formData).forEach(key => { params.append(key, formData[key]); }); try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest', 'User-Agent': 'Mozilla/5.0 (compatible; WebScraper/1.0)' }, body: params, credentials: 'include' // Include cookies }); if (!response.ok) { throw new Error(`HTTP error!
🌐
YouTube
youtube.com › codelines
python requests post application x www form urlencoded - YouTube
Instantly Download or Run the code at https://codegive.com sure, i'd be happy to provide a tutorial on using python requests to make a post request with the...
Published   February 20, 2024
Views   745
🌐
ScrapeOps
scrapeops.io › home › python web scraping playbook › python requests post requests
Python Requests - How to Send POST Requests | ScrapeOps
April 12, 2023 - The requests library will automatically encode the data as JSON and set the Content-Type header to application/x-www-form-urlencoded so you don't have to set any headers.
🌐
ReqBin
reqbin.com › code › python › ighnykth › python-requests-post-example
How do I send a POST request using Python Requests Library?
Below is an example of posting an HTML form using the Python Requests library to the ReqBin echo URL: ... import requests url = "https://reqbin.com/echo/post/form" data = "key1=value1&key2=value2" headers = {'Content-Type': 'application/x-www-form-urlencoded'} r = requests.post(url, data=data, headers=headers) print(r.text)
🌐
Reddit
reddit.com › r/learnpython › how do i format a url post request?
r/learnpython on Reddit: How do I format a URL POST request?
September 14, 2023 -

I'm trying to access data from Yahoo's API and got setup with all the credentials. I'm following their official documentation and am on Step 4 here, but am confused.

This is what I have. I've tried putting together a full URL as well and just doing a requests.post('https://fullurl.com') but that didn't work either.

import requests

consumer_key = credentials.consumer_key
consumer_secret = credentials.consumer_secret

headers = {'content-type': 'application/x-www-form-urlencoded'}
data = {"client_id": consumer_key,
		"client_secret": consumer_secret
		}
response = requests.post(f"https://api.login.yahoo.com/oauth2/get_token",
						 headers=headers,
						 params=data
						 )

The error I'm getting is: b'{"error":"INVALID_INPUT","error_description":"client id cannot be empty"}' Should I be putting the data or headers as another parameter? Not sure what to try

🌐
ProxiesAPI
proxiesapi.com › articles › sending-form-data-with-python-requests
Sending Form Data with Python Requests | ProxiesAPI
JSON is a popular format for passing structured data. To send JSON, pass your Python dict to the ... data = { 'name': 'John Doe', 'hobbies': ['hiking', 'diving'] } response = requests.post(url, json=data)
🌐
YouTube
youtube.com › watch
python requests post form urlencoded - YouTube
Instantly Download or Run the code at https://codegive.com certainly! below is an informative tutorial about making a post request with python's requests li...
Published   September 18, 2023
🌐
GitHub
github.com › psf › requests › issues › 1608
"Content-Type header: application/x-www-form-urlencoded" won't be overridden · Issue #1608 · psf/requests
April 30, 2013 - Simple test under Python 3.3.2, using the current 2.0 branch of requests (same behaviour with requests-1.2.3 btw); inspecting request headers with requestb.in. The Content-Type header contains two entries. I expected my stipulated header to override (replace) application/x-www-form-urlencoded. import requests data = open('C:/my_audio_files\sample_50.wav', 'rb').read() response = requests.post(url = "http://requestb.in/183gv9g1" data=data, headers={'Content-Type': 'application/octet-stream'} ) FORM/POST PARAMETERS ·
Author   sebastien-bratieres
🌐
Oreate AI
oreateai.com › blog › unpacking-applicationxwwwformurlencoded-pythons-key-to-web-form-data › 38d26553f03cc3338279167161cbd409
Unpacking `Application/X-WWW-Form-Urlencoded`: Python's Key to Web Form Data - Oreate AI Blog
1 month ago - } response = requests.post(url, data=payload) print(response.text) Behind the scenes, requests will take that payload dictionary and convert it into username=test_user&email=test@example.com&message=Hello+there!, setting the Content-Type header to application/x-www-form-urlencoded automatically. It's this kind of thoughtful design that makes Python such a joy for web development.