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
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
[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
How do I format a URL POST request?
data=data instead of params=data Using data= will also set the content-type headers, so you can take that out. More on reddit.com
🌐 r/learnpython
3
1
September 11, 2023
People also ask

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
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
How can I upload a file with Python Requests POST?
Use files with an open file handle (filename, fileobj, mime). Requests builds a multipart/form-data body for you.
🌐
scrapingbee.com
scrapingbee.com › blog › how-to-send-post-python-requests
How to send a POST with Python Requests? | ScrapingBee
🌐
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.
🌐
ScrapingDog
scrapingdog.com › blog › send-post-python-requests
How To Send A Post Requests in Python?
October 2, 2024 - 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 while submitting a form.
🌐
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
Find elsewhere
🌐
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
🌐
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 11, 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

🌐
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 › psf › requests › issues › 1608
"Content-Type header: application/x-www-form-urlencoded" won't be overridden · Issue #1608 · psf/requests
April 27, 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
🌐
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.
🌐
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.
🌐
Python
docs.python.org › 3 › library › urllib.request.html
urllib.request — Extensible library for opening URLs — Python ...
For an HTTP POST request method, data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.parse.urlencode() function takes a mapping or sequence of 2-tuples and returns an ASCII string in this format.
🌐
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: POST HTML Form Example · 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) In this example, the "import requests" directive imports the Requests library to our Python code.
🌐
Crifan
crifan.com › post_type_application_x_www_form_urlencoded_data_for_python_requests
【已解决】Python中requests的POST发送类型application/x-www-form-urlencoded的数据 – 在路上
January 8, 2020 - # Function: Demo requests # Author: Crifan Li # Update: 20200303 import json import requests postUrl = "http://httpbin.org/post" postDataDict = { "ebookId": "52365" } gContentTypeList = [ "application/x-www-form-urlencoded", "application/json" ] for curContentType in gContentTypeList: print("%s post: %s %s" % ('-'*20, curContentType, '-'*20)) curHeaders = { "Content-Type": curContentType } print("curHeaders=%s" % curHeaders) if curContentType == "application/json": curPostData = json.dumps(postDataDict) else: curPostData = postDataDict print("curPostData=%s" % curPostData) resp = requests.post
🌐
Python.org
discuss.python.org › python help
Post request not work - Python Help - Discussions on Python.org
May 12, 2021 - Hi all, I’m working with request library using post: if I run: url = "\"https://server.com/admin/api/api?format=json2&X-API-KEY=internal_batch\"" headers = "\"Content-Type: application/x-www-form-urlencoded\"" data = "\"payload\"=" data += "\'[{\"timestamp\": " + str(1624872100) + ", \"lat\": " + str(0) + ", \"lon\": " + str(0) + "}]\'" command = "curl -X POST -H " + headers + " -d " + data + " " + url r = os.system(command) it works. but if I run: API_PROD_URL = "https://server.com/admin"...
🌐
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   February 23, 2024
🌐
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!