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
🌐
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.
Discussions

How to structure a raw body in x-www-form-urlencoded format
Hello, I’m trying to use the twitter media API to upload an image and i’m struggling to understand how Postman is encoding the variables when using the x-www-form-urlencoded body type. If i create a variable ‘media=iVB… More on community.postman.com
🌐 community.postman.com
1
0
April 24, 2024
Highest scored 'x-www-form-urlencoded' questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
Newest 'x-www-form-urlencoded' Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
How to properly parse x-www-form-urlencoded data on server side?
Use Content-Type: application/json More on reddit.com
🌐 r/node
19
3
October 2, 2024
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
Can I use Python Requests POST with sessions and authentication?
Yep. Use requests.Session to persist cookies and headers; set your Authorization header once and reuse it across post requests.
🌐
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
🌐
ScrapingDog
scrapingdog.com › blog › send-post-python-requests
How To Send A Post Requests in Python?
October 2, 2024 - You can even read our complete guide on web scraping with Python to get a complete idea of how headers actually function. Let’s say you want to scrape something that is behind an auth wall. That auth wall consists of a simple form that expects the correct username and password from you. This can be easily done using POST request. You just need to use the correct content type. Generally, the value of the content-type header is application/x-www-form-urlencoded ...
🌐
YouTube
youtube.com › codelines
python requests post application x www form urlencoded - YouTube
February 20, 2024 - 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...
🌐
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, ...
Find elsewhere
🌐
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
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components
The resulting string is a series of key=value pairs separated by '&' characters, where both key and value are quoted using the quote_via function. By default, quote_plus() is used to quote the values, which means spaces are quoted as a '+' character and ‘/’ characters are encoded as /, which follows the standard for GET requests (application/x-www-form-urlencoded).
🌐
YouTube
youtube.com › watch
How to Send a POST Request with x-www-form-urlencoded Body - YouTube
December 8, 2024 - How to Send a POST Request with x-www-form-urlencoded BodyIn this tutorial, you will learn how to send a POST request with x-www-form-urlencoded body using v...
🌐
Slack
docs.slack.dev › methods › chat.postmessage
chat.postMessage method | Slack Developer Docs
The method was called via a POST request, but the specified Content-Type was invalid. Valid types are: application/json application/x-www-form-urlencoded multipart/form-data text/plain.
🌐
Binance
developers.binance.com › general info
General Info | Binance Open Platform
For POST, PUT, and DELETE endpoints, the parameters may be sent as a query string or in the request body with content type application/x-www-form-urlencoded.
🌐
GitHub
github.com › psf › requests › issues › 2071
On Python 3, sending bytes automatically choses 'x-www-form-urlencoded' as the content_type · Issue #2071 · psf/requests
Project: openstack/python-swiftclient 74eb91b176464dcac225e7b8152e3a933fdf30ee Do not set Content-Type to '' with new requests. Previously, python-swiftclient worked around a requests issue where Content-Type could be set to application/x-www-form-urlencoded when using python3.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › HTTP › Guides › CORS
Cross-Origin Resource Sharing (CORS) - HTTP | MDN
Apart from the headers automatically set by the user agent (for example, Connection, User-Agent, or the forbidden request headers), the only headers which are allowed to be manually set are the CORS-safelisted request-headers, which are: Accept · Accept-Language · Content-Language · Content-Type (please note the additional requirements below) Range (only with a single range header value; e.g., bytes=256- or bytes=127-255) The only type/subtype combinations allowed for the media type specified in the Content-Type header are: application/x-www-form-urlencoded ·
🌐
Stack Overflow
stackoverflow.com › questions › tagged › x-www-form-urlencoded
Highest scored 'x-www-form-urlencoded' questions - Stack Overflow
The request is working well, it should look like this : Bulk Edit Mode : Key-Value Edit mode : There are also 9 headers that are ... ... 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 ...
🌐
Stack Overflow
stackoverflow.com › questions › tagged › x-www-form-urlencoded
Newest 'x-www-form-urlencoded' Questions - Stack Overflow
I have a sequence where i start by doing a url encoded REST call followed by a json api rest call as follows: <payloadFactory media-type="xml"> <format> <soapenv:... ... I have a request which need to be sent in Postman as urlencoded value like in the following (I changed some value just to ...
🌐
Apidog
apidog.com › blog › x-www-form-urlencoded-vs-json
Application/x-www-form-urlencoded VS Application/json: Which One to Use?
August 13, 2024 - These practical examples showcase how to implement each format, underlining the ease of use of Axios for both scenarios. For developers looking for an easy way to work with application/x-www-form-urlencoded and application/json formats, Apidog is an ideal tool. This API development and testing platform allows users to send requests in both formats smoothly.
🌐
Chilkat
chilkatsoft.com › http_post_url_encoded.asp
HTTP POST URL Encoded
curl -X POST https://example.com/v2/reports \ -H "Authorization: Bearer [YOUR_ACCESS_TOKEN]" \ -H "Accept: application/json" \ -H "Host: example.com" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "endDate=2015-12-31" \ -d "filters=video==jb42oy5_ruI" \ -d "ids=channel==MINE" \ -d "metrics=views,comments,likes,dislikes,estimatedMinutesWatched,averageViewDuration" \ -d "startDate=2015-01-01" \ -d "key=[YOUR_API_KEY]"
🌐
FastAPI
fastapi.tiangolo.com › tutorial › request-files
Request Files - FastAPI
Data from forms is normally encoded using the "media type" application/x-www-form-urlencoded when it doesn't include files.
🌐
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
When working with browser automation tools, you might need to handle AJAX requests using Puppeteer or handle authentication in Puppeteer for more complex scenarios involving JavaScript-heavy applications. Always ensure the correct Content-Type header is set: # Correct approach headers = {'Content-Type': 'application/x-www-form-urlencoded'} response = requests.post(url, data=form_data, headers=headers) # The requests library sets this automatically when using 'data' parameter response = requests.post(url, data=form_data) # Recommended