You can use requests.utils.quote (which is just a link to urllib.parse.quote) to convert your text to url encoded format.

Copy>>> import requests
>>> requests.utils.quote('test+user@gmail.com')
'test%2Buser%40gmail.com'
Answer from MohitC on Stack Overflow
🌐
Python
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components
The resulting string is a series ... as a '+' character and ‘/’ characters are encoded as /, which follows the standard for GET requests (application/x-www-form-urlencoded)....
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
1
0
February 18, 2022
How to avoid URL encoding done by requests library while generating API key through XML version of Panorama API. Is there an alternate way of generating API without using the requests library?
In python I use urllib.parse.quote.. It works perfectly Use the request library to make the call More on reddit.com
🌐 r/paloaltonetworks
3
1
January 17, 2023
Suggestion: Improve `urlencode()` handling of boolean values - Ideas - Discussions on Python.org
Background urllib.parse.urlencode() currently converts boolean values using str(), resulting in query parameters like: urlencode({'is_active': True}) # -> "is_active=True" While technically correct in Python, this behavior is often counterintuitive in web contexts, where: • True is usually ... More on discuss.python.org
🌐 discuss.python.org
1
April 8, 2025
How to url encode User Search Query Syntax for Management API in Python
I am trying to url encode this query string: email:john* and after quoting the string using Python urllib.parse.quote() my final URL looks like this: https://{domain}/api/v2/users?q=email:john* but the search doesn’t work because urllib.parse.quote() is also quoting the * which isn’t supposed ... More on community.auth0.com
🌐 community.auth0.com
1
0
January 26, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-urlencode-a-querystring-in-python
How to Urlencode a Querystring in Python? - GeeksforGeeks
July 23, 2025 - Below are the possible approaches to urlencode a querystring in Python. Using urllib.parse.urlencode · Using requests library · Using urllib.parse.quote_plus for Custom Encoding · In this example, we are using urllib.parse.urlencode from the urllib.parse module to URL-encode a dictionary.
🌐
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 ·
🌐
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.
🌐
Python
docs.python.org › 3 › library › urllib.request.html
urllib.request — Extensible library for opening URLs
Note that params output from urlencode ... as data: >>> import urllib.request >>> import urllib.parse >>> data = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> data = data.encode('ascii') >>> with urllib.request.urlopen("https://httpbin.org/post", data) as f: ...
Find elsewhere
🌐
Python.org
discuss.python.org › ideas
Suggestion: Improve `urlencode()` handling of boolean values - Ideas - Discussions on Python.org
April 8, 2025 - Background urllib.parse.urlencode() currently converts boolean values using str(), resulting in query parameters like: urlencode({'is_active': True}) # -> "is_active=True" While technically correct in Python, this behavior is often counterintuitive ...
🌐
Auth0
community.auth0.com › get help
How to url encode User Search Query Syntax for Management API in Python - Auth0 Community
January 26, 2024 - I am trying to url encode this query string: email:john* and after quoting the string using Python urllib.parse.quote() my final URL looks like this: https://{domain}/api/v2/users?q=email:john* but the search doe…
🌐
ProxiesAPI
proxiesapi.com › articles › handling-url-encoding-in-python-requests
Handling URL Encoding in Python Requests | ProxiesAPI
March 2, 2024 - The solution is to manually URL encode the parameters before making the request. The · quote_plus function from Python's urllib can be used:
🌐
GitHub
github.com › psf › requests › issues › 369
requests.get() URL Encode Issue · Issue #369 · psf/requests
January 20, 2012 - Hi, I noticed URL encode issue in get() -- In [32]: r = requests.get(r'http://i.ebayimg.com/00/s/ODAzWDEyODA=/$(KGrHqV,!o8E63YcElkoBPFMhH2vUQ~~60_1.JPG') In [33]: r.status_code Out[33]: 404 In [34]: r = urllib2.urlopen("http://i.ebayim...
Author   psf
🌐
Devzery
devzery.com › post › urlencode-python-mastering-url-encoding-in-python
Python URL Encoding Made Simple: Learn urlencode, Query Strings & API Handling!
April 21, 2025 - In this example, the urlencode function converts the dictionary into a properly formatted query string, with spaces encoded as + and the & character separating the parameters. Special characters need to be carefully handled when encoding · URLs. For example, if your query contains characters like &, #, or /, they must be encoded to ensure the URL is valid: ... params = {'q': 'python & django', 'lang': 'en#us'} query_string = urlencode(params) print(query_string)
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.34.2 documentation
May 18, 2026 - >>> bad_r = requests.get('https://httpbin.org/status/404') >>> bad_r.status_code 404 >>> bad_r.raise_for_status() Traceback (most recent call last): File "requests/models.py", line 832, in raise_for_status raise http_error requests.exceptions.HTTPError: 404 Client Error · But, since our status_code for r was 200, when we call raise_for_status() we get: ... All is well. We can view the server’s response headers using a Python dictionary:
🌐
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 while submitting a form.
Top answer
1 of 3
200

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:

Copydata = {'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:

Copy$ nc -kl 8765

In another:

Copy$ 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):

Copyspam=20&eggs=3

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

Copy{"spam": 20, "eggs": 3}
2 of 3
17

Short answer with example:

Copyimport requests

the_data = {"aaa": 1, "bbb": 2, "ccc": "yeah"}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# Execute the post
requests.post("http://bla.bla.example.com", data=the_data, headers=headers)
# You have POSTed this HTTP body: aaa=1&bbb=2&ccc=yeah (note, although the content-type is called urlencoded the data is not in the URL but in the http body)
# to this url: "http://bla.bla.example.com"

Requests library does all the JSON to urlencoded string conversion for you

References:

MDN Web docs, Requests lib post url-encoded form

🌐
CSDN
devpress.csdn.net › python › 63044efec67703293080abf9.html
How to prevent python requests from percent encoding my URLs?_python_Mangs-Python
August 23, 2022 - import requests import urllib.parse payload = { 'format': 'json', 'key': 'site:dummy+type:example+group:wheel' } payload_str = urllib.parse.urlencode(payload, safe=':+') # 'format=json&key=site:dummy+type:example+group:wheel' url = 'https://httpbin.org/get' r = requests.get(url, params=payload_str) print(r.text)
🌐
ProxiesAPI
proxiesapi.com › articles › properly-encode-urls-in-python-requests-with-urllib
Properly Encode URLs in Python Requests with urllib | ProxiesAPI
February 20, 2024 - from urllib.parse import quote_plus base = 'https://www.example.com?' params = 'q=python+learning&type=tips' encoded_params = quote_plus(params) url = base + encoded_params print(url) # https://www.example.com?q=python+learning&type=tips · This allows encoding only the user-supplied parts of the URL. If an invalid character is encountered during encoding, a · UnicodeEncodeError may be raised. You can handle this by specifying an ... Properly encoding URLs is crucial for transmitting requests properly.
🌐
Reddit
reddit.com › r/webdev › problem trying to convert a curl example to a python request
r/webdev on Reddit: Problem trying to convert a Curl example to a python request
April 7, 2022 - import os import requests GINGR_KEY = os.environ["GINGR_KEY"] ANIMALS_URL = "https://{your_app}.gingrapp.com/api/v1/animals" headers = {'Content-Type': 'application/x-www-form-urlencoded'} params = {"key": GINGR_KEY, "params": {"first_name": "Bella"}} response = requests.get(ANIMALS_URL, headers=headers, params=params)
🌐
ScrapeOps
scrapeops.io › url encoding
URL Encoding | ScrapeOps
import requests from urllib.parse import urlencode proxy_params = { 'api_key': 'YOUR_API_KEY', 'url': 'https://example.com/?test=hello', } response = requests.get( url='https://proxy.scrapeops.io/v1/', params=urlencode(proxy_params), timeout=120, )