Python 3

In Python 3, the urllib package has been broken into smaller components. You'll use urllib.parse.quote_plus (note the parse child module)

import urllib.parse
safe_string = urllib.parse.quote_plus(...)

Python 2

What you're looking for is urllib.quote_plus:

safe_string = urllib.quote_plus('string_of_characters_like_these:$#@=?%^Q^$')

#Value: 'string_of_characters_like_these%3A%24%23%40%3D%3F%25%5EQ%5E%24'
Answer from Ricky Sahu on Stack Overflow
🌐
URL Encoder
urlencoder.io › python
How to encode URLs in Python | URLEncoder
>>> import urllib.parse >>> params = {'q': 'Python URL encoding', 'as_sitesearch': 'www.urlencoder.io'} >>> urllib.parse.urlencode(params) 'q=Python+URL+encoding&as_sitesearch=www.urlencoder.io'
FAQ
URL Encode online. URLEncoder is a simple and easy to use online tool to convert any string to URL Encoded format in real time. It also contains several articles on how to URL Encode a query string or form parameter in different programming languages.
Blog
Java provides a URLEncoder class that contains static methods to URL encode and decode a string. ... Javascript URL Encoding example. Learn how to URL Encode a String in Javascript. You can encode URI components like query strings or path segments using the encodeURIComponent() function. ... Python ...
🌐
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. ... 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.3 ...
Use the urllib.parse.urlencode() function to convert such lists of pairs into query strings. Changed in version 3.2: Add encoding and errors parameters. Changed in version 3.8: Added max_num_fields parameter. Changed in version 3.10: Added separator parameter with the default value of &. Python versions earlier than Python 3.10 allowed using both ; and & as query parameter separator.
🌐
Urlencoder
urlencoder.net › python-urlencode
Python urlencode() - URL Encode
>>> import urllib >>> params = urllib.urlencode( {'param': 'url encoder'} ) >>> print "http://example.com/?" + params
🌐
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.
🌐
GitHub
gist.github.com › nkentaro › 37f25b802e825da7ab3b7f27c0303047
url encode and decode in python3 · GitHub
The quote() function encodes space to . Python also has a quote_plus() function that encodes space to plus sign (+). I've written about URL Encoding in python on my website.
🌐
Delft Stack
delftstack.com › home › howto › python › python urlencode
How to Use Urlencode in Python | Delft Stack
February 15, 2024 - Now let’s say our query string, which is in the form of a dictionary, contains multi-valued data like an attribute named colors with values blue, pink, and green, so it’s a multi-valued attribute. We can also URL encode such dictionaries in Python. The urlencode() function takes an optional argument doseq.
Find elsewhere
🌐
iO Flood
ioflood.com › blog › python-url-encode
[SOLVED] Python URL Encode Using urllib.parse Functions
February 1, 2024 - In this example, we first define a dictionary params that contains our query parameters. 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 Encode
urlencoder.org › enc › python
URL Encoding of "python" - Online
Encode python to URL-encoded format with various advanced options. Our site has an easy to use online tool to convert your data.
🌐
W3docs
w3docs.com › python
How to urlencode a querystring in Python?
You can use the urllib.parse.urlencode() function to urlencode a querystring in Python. Here is an example of how to use the function to urlencode a querystring with multiple parameters:
🌐
URLDecoder
urldecoder.io › python
URL Decoding query strings or form parameters in Python | URLDecoder
>>> import urllib >>> queryStr = 'Hellö+Wörld@Python' >>> urllib.unquote(queryStr) 'Hell\xc3\xb6+W\xc3\xb6rld@Python'
🌐
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 - 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) ...
🌐
Python
docs.python.org › 3.3 › library › urllib.parse.html
21.8. urllib.parse — Parse URLs into components — Python 3.3.7 documentation
Example: unquote_to_bytes('a&�') yields b'a&\xef'. urllib.parse.urlencode(query, doseq=False, safe='', encoding=None, errors=None)¶
🌐
Linux Hint
linuxhint.com › urlencode-python
How to urlencode in Python? – Linux Hint
Execution of this file takes place at the terminal via the python3 query as below. The output result is showing the encoding of a string successfully. ... In the above example, you have seen that we have used the quote() function to encode or quote a string-type variable, and it worked perfectly. On the other hand, you need to understand that we cannot apply the “urlencode...
🌐
docs.python.org
docs.python.org › 3 › library › urllib.html
urllib — URL handling modules
Source code: Lib/urllib/ urllib is a package that collects several modules for working with URLs: urllib.request for opening and reading URLs, urllib.error containing the exceptions raised by urlli...
🌐
ProxiesAPI
proxiesapi.com › articles › encoding-urls-with-python-s-urllib
Encoding URLs with Python's urllib | ProxiesAPI
February 6, 2024 - import urllib.parse params = {'q': 'python urllib', 'type': 'articles', 'sort': 'relevance'} url = 'https://www.example.com/search?' + urllib.parse.urlencode(params) print(url)
🌐
ScrapeOps
scrapeops.io › url encoding
URL Encoding | ScrapeOps
import urllib.parse encoded_url ... timeout=120, ) This is how you would encode a URL with encodeURIComponent: const encodedUrl = encodeURIComponent('https://example.com/?test=hello'); Here is an alternative method using the querystring library in a request-promise ...
🌐
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 doesn’t work because ...