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

>>> import requests
>>> requests.utils.quote('[email protected]')
'test%2Buser%40gmail.com'
Answer from MohitC on Stack Overflow
🌐
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.
🌐
Python
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components — Python 3.14.6 ...
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)....
🌐
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)
🌐
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 ·
🌐
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:
🌐
Delft Stack
delftstack.com › home › howto › python › python urlencode
How to Use Urlencode in Python | Delft Stack
February 15, 2024 - In Python, we can URL encode a query string using the urlib.parse module, which further contains a function urlencode() for encoding the query string in the URL, and the query string is simply a string of key-value pairs.
🌐
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, )
Find elsewhere
🌐
Compciv
compciv.org › guides › python › how-tos › creating-proper-url-query-strings
Creating URL query strings in Python | Computational Methods in the Civic Sphere at Stanford University
February 9, 2016 - (assuming you've read the short guide on making functions: Function fundamentals in Python) Here's a bare-bones implementation, in which a user only has to specify a list (or just a string, if there's only one location) of locations and, optionally, width and height. The foo_goo_url function does the work of serializing the input into proper Google Static Maps API format. At the end, it returns the URL as a string object: def foogoo_url(locations, width = 600, height = 400): from urllib.parse import urlencode gmap_url = 'https://maps.googleapis.com/maps/api/staticmap' size_str = str(width) + 'x' + str(height) query_str = urlencode({'size': size_str, 'markers': locations}, doseq=True) return gmap_url + '?' + query_str
🌐
jdhao's digital space
jdhao.github.io › 2020 › 07 › 09 › requests_notes
Note on Using requests package · jdhao's digital space
February 7, 2021 - The request body is: apple=10&pear=20&pear=30&img=http://example.com/demo.jpg · We can also encode JSON directly using urllib: import urllib payload = {"apple": 10, "pear": [20, 30], "img": "http://example.com/demo.jpg"} print(urllib.parse.urlencode(payload, doseq=True)) The encoded string is the same. Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST · Python requests module: urlencoding json data ·
🌐
iO Flood
ioflood.com › blog › python-url-encode
[SOLVED] Python URL Encode Using urllib.parse Functions
February 1, 2024 - When we pass this dictionary to the urlencode() function, it returns a new string where all special characters have been replaced with their corresponding percent-encoded ASCII characters. This is a more advanced method for URL encoding in Python, as it allows you to handle URLs that include query parameters.
🌐
URL Encoder
urlencoder.io › python
How to encode URLs in Python | URLEncoder
>>> import urllib.parse >>> query = 'Hellö Wörld@Python' >>> urllib.parse.quote_plus(query) 'Hellö+Wörld@Python' ... You can encode multiple parameters at once using urllib.parse.urlencode() function. This is a convenience function which takes a dictionary of key value pairs or a sequence ...
🌐
w3resource
w3resource.com › python-exercises › urllib3 › python-urllib3-exercise-11.php
Constructing URL: Proper Query Parameter Encoding
September 3, 2025 - Python Code : # Import the urllib3 library import urllib3 # Define the base URL without query parameters base_url = 'https://example.com/api' # Define the query parameters as a dictionary query_params = { 'param1': 'value1', 'param2': 'value2', 'param3': 'special character: $', } # Use the urllib3 urlencode function to encode the query parameters encoded_params = urllib3.request.urlencode(query_params) # Combine the base URL and encoded query parameters to form the complete URL complete_url = f"{base_url}?{encoded_params}" # Print the complete URL print(f"Complete URL: {complete_url}") Sample
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-pass-parameters-in-url-with-python
How to Pass Parameters in URL with Python - GeeksforGeeks
July 23, 2025 - In Python, this is usually done using libraries like requests for making HTTP requests or urllib . Let's understand how to pass parameters in a URL with this example. ... import urllib.parse params = {'name': 'shakshi', 'age': 21} url = ...
Top answer
1 of 1
18

The spaces are not the problem; your method of generating the query string is, as is your actual JSON payload.

Note that your original URL has a different JSON structure:

>>> from urllib import unquote
>>> unquote('%7B%22rajNames%22%3A%5B%22WAR%22%5D%7D')
'{"rajNames":["WAR"]}'

The rajNames parameter is a list, not a single string.

Next, requests sees all data in params as a new parameter, so it used & to delimit from the previous parameter. Use a dictionary and leave the ?jsonRequest= part to requests to generate:

headers = {'Accept': 'application/json', 'Authorization': 'Bearer '+access_token}
json_data = {'rajNames': ['WAR']}
params = {'jsonRequest': json.dumps(json_data)}
url = 'http://258.198.39.215:8280/areas/0.1/get/raj/name'
r = requests.get(url, params=params, headers=headers)
print _r.url

Demo:

>>> import requests
>>> import json
>>> headers = {'Accept': 'application/json', 'Authorization': 'Bearer <access_token>'}
>>> json_data = {'rajNames': ['WAR']}
>>> params = {'jsonRequest': json.dumps(json_data)}
>>> url = 'http://258.198.39.215:8280/areas/0.1/get/raj/name'
>>> requests.Request('GET', url, params=params, headers=headers).prepare().url
'http://258.198.39.215:8280/areas/0.1/get/raj/name?jsonRequest=%7B%22rajNames%22%3A+%5B%22WAR%22%5D%7D'

You can still eliminate the spaces used in the JSON output from json.dumps() by setting the separators argument to (',', ':'):

>>> json.dumps(json_data)
'{"rajNames": ["WAR"]}'
>>> json.dumps(json_data, separators=(',', ':'))
'{"rajNames":["WAR"]}'

but I doubt that is really needed.

🌐
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