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
🌐
GitHub
gist.github.com › SpotlightKid › eca9b00239104e8c599b86635f62ab73
Making a POST request with url or form-encoded params with MicroPython · GitHub
urlencode.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ·
Discussions

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 so I search a little bit and It should work just setting request_body as a dictionary. More on stackoverflow.com
🌐 stackoverflow.com
February 3, 2024
[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. This adds an extra step and can be a point of confusion, especially for users transitioning from libraries like requests in Python ... More on github.com
🌐 github.com
2
September 27, 2023
flask - How to send urlencoded parameters in POST request in python - Stack Overflow
It is showing an error in this line as I guess data=params is not in proper format. Is there any way to POST the urlencoded parameters to an API? ... Simply pass in a dict to data, requests by default will take care of sending it as x-www-form-urlencoded. More on stackoverflow.com
🌐 stackoverflow.com
September 14, 2023
"Content-Type header: application/x-www-form-urlencoded" won't be overridden
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. More on github.com
🌐 github.com
10
April 30, 2013
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
🌐
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.
🌐
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 16, 2022
Views   745
🌐
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).
🌐
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
🌐
ScrapingDog
scrapingdog.com › blog › send-post-python-requests
How To Send A Post Requests in Python?
April 24, 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.
🌐
FastAPI
fastapi.tiangolo.com › tutorial › request-forms
Form Data - FastAPI
July 23, 2025 - 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.
🌐
Scrapfly
scrapfly.io › blog › posts › how-to-python-requests-post
Guide to Python requests POST method
October 2, 2024 - 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.
🌐
jdhao's digital space
jdhao.github.io › 2020 › 07 › 09 › requests_notes
Note on Using requests package · jdhao's digital space
November 29, 2022 - request headers: {'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '69', 'Content-Type': 'application/json'} request body: b'{"apple": 10, "pear": [20, 30], "img": "http://example.com/demo.jpg"}' ... When making requests using json data in requests.post(url, data=json_dict), the Content-Type is application/x-www-form-urlencoded...
🌐
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 - Content-Length: 38206 User-Agent: python-requests/1.2.3 CPython/3.3.2 Windows/8 Connection: close Host: requestb.in Content-Type: application/octet-stream, application/x-www-form-urlencoded Accept: / Accept-Encoding: identity, gzip, deflate, compress
Author   sebastien-bratieres
🌐
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 26, 2025 -

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

🌐
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
November 18, 2024 - 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
🌐
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.
🌐
Python Forum
python-forum.io › thread-38828.html
Python request (post/get)
November 29, 2022 - Is using requests post method the correct way to fill in a search box on a website? I have been reading the docs and they all seem to suggest using the requests get method adding the search query to the url. The problem I have is the website uses a...
🌐
Real Python
realpython.com › python-requests
Python's Requests Library (Guide) – Real Python
July 23, 2025 - You make a GET request in Python using requests.get() with the desired URL. To add headers to requests, pass a dictionary of headers to the headers parameter in your request. To send POST data, use the data parameter for form-encoded data or the json parameter for JSON data.
🌐
ProxiesAPI
proxiesapi.com › articles › sending-form-data-with-python-requests
Sending Form Data with Python Requests | ProxiesAPI
Additionally, check response status codes and inspect request headers to ensure form data is encoded properly. Hopefully this guide provides a comprehensive overview of how to effectively send JSON, multipart, and form-url encoded data with Python Requests!
🌐
urllib3
urllib3.readthedocs.io › en › 1.26.3 › reference › urllib3.request.html
Request Methods - urllib3 1.26.3 documentation
April 30, 2013 - This is useful for request methods like POST, PUT, PATCH, etc. When encode_multipart=True (default), then urllib3.encode_multipart_formdata() is used to encode the payload with the appropriate content type. Otherwise urllib.parse.urlencode() is used with the ‘application/x-www-form-urlencoded’ content type.