You misread the documentation. You need to do two things:

  1. Quote each key and value from your dictionary, and
  2. Encode those into a URL

Luckily urllib.parse.urlencode does both those things in a single step, and that's the function you should be using.

from urllib.parse import urlencode, quote_plus

payload = {'username':'administrator', 'password':'xyz'}
result = urlencode(payload, quote_via=quote_plus)
# 'password=xyz&username=administrator'
Answer from Adam Smith on Stack Overflow
🌐
WebScraping.AI
webscraping.ai › faq › urllib3 › how-do-i-encode-query-parameters-with-urllib3
How do I encode query parameters with urllib3? | WebScraping.AI
import urllib3 from urllib.parse import urlencode # Initialize connection pool manager http = urllib3.PoolManager() # Define query parameters query_params = { 'search': 'web scraping', 'category': 'python tools', 'page': 1, 'active': True } # Encode parameters encoded_params = urlencode(query_params) print(f"Encoded: {encoded_params}") # Output: search=web+scraping&category=python+tools&page=1&active=True # Construct URL and make request url = f'https://api.example.com/search?{encoded_params}' response = http.request('GET', url) print(f"Status: {response.status}") print(f"Data: {response.data.decode('utf-8')}")
🌐
Python
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components — Python 3.14.3 documentation
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.
Discussions

urllib - How to urlencode a querystring in Python? - Stack Overflow
I prefer urllib.parse.quote() myself since it uses rather than +. 2015-09-29T20:43:45.753Z+00:00 ... urlencode won't work because it only works on dictionaries. quote_plus didn't produce the correct output. ... That's really helpful! In my case, I only have a portion of string that I want to URL-encode, for example I want to transform my string to my string. Your solution works like a charm for that! 2016-02-14T11:27:02.76Z+00:00 ... In Python 3... More on stackoverflow.com
🌐 stackoverflow.com
python - 'module' has no attribute 'urlencode' - Stack Overflow
>>> import urllib >>> params = ... >>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query", params) >>> print f.read() ... Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'urlencode' ... The "2" in your URL. ... Sign up to request clarification or add additional context in comments. ... You use the Python 2 docs but write your program in Python 3... More on stackoverflow.com
🌐 stackoverflow.com
python - urllib3.urlencode googlescholar url from string - Stack Overflow
I am trying to encode a string to url to search google scholar, soon to realize, urlencode is not provided in urllib3. >>> import urllib3 >>> string = "https://scholar.google.com/ More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
URL Encoder
urlencoder.io › python
How to encode URLs in Python | URLEncoder
In Python 3+, You can URL encode any string using the quote() function provided by urllib.parse package.
🌐
GitHub
gist.github.com › nkentaro › 37f25b802e825da7ab3b7f27c0303047
url encode and decode in python3 GitHub
Save nkentaro/37f25b802e825da7ab3b7f27c0303047 to your computer and use it in GitHub Desktop. ... 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 ... The quote() function encodes space to . Python also has a quote_plus() function that encodes space to plus sign (+).
🌐
urllib3
urllib3.readthedocs.io › en › 1.26.3 › reference › urllib3.request.html
Request Methods - urllib3 1.26.3 documentation
... request_encode_url() is for sending requests whose fields are encoded in the URL (such as GET, HEAD, DELETE). request_encode_body() is for sending requests whose fields are encoded in the body of the request using multipart or www-form-urlencoded (such as for ...
Find elsewhere
🌐
Linux Hint
linuxhint.com › urlencode-python
How to urlencode in Python? – Linux Hint
We have used the dictionary “l” in the parameter of a “urlencode” method with “doseq” value as “True” to avoid special characters in our output. After that, we have printed the encoded value. Save your file using “Ctrl+S” and hit the cross button on the right corner of the file window to quit it. #!/usr/bin/python import urllib.parse l = { 'Name': 'Aqsa', 'Salary': [ 50000, 80000]} new = urllib.parse.urlencode(l, doseq=True) print(new)
🌐
Delft Stack
delftstack.com › home › howto › python › python urlencode
How to Use Urlencode in Python | Delft Stack
February 15, 2024 - In Python, the urllib.parse module, featuring the urlencode() function, offers a convenient method for encoding query strings in URL format. This function accepts dictionaries as input, converting key-value pairs into the required encoded URL.
🌐
iO Flood
ioflood.com › blog › python-url-encode
[SOLVED] Python URL Encode Using urllib.parse Functions
February 1, 2024 - While Python’s quote() and urlencode() functions encode most special characters, they don’t encode all of them by default. This is because some special characters, such as ‘/’, ‘:’, and ‘?’, are used to separate different parts of a URL. If you need to encode these characters, you can use the quote() function with the safe parameter set to an empty string. Here’s an example: from urllib.parse import quote url = 'https://www.example.com?param=special/char:another?char' encoded_url = quote(url, safe='') print(encoded_url) # Output: # 'https://www.example.com?param=special/char:another?char'
🌐
Quora
quora.com › What-does-urllib-urlencode-returns
What does urllib.urlencode() returns? - Quora
Answer (1 of 4): Basically urllib provides urlencode method which is used for fetching urls. You can do pretty much lot of changes while fetching the url via urllib. Suppose you wanted to open a website which takes some extra parameters in the ...
🌐
w3resource
w3resource.com › python-exercises › urllib3 › python-urllib3-exercise-11.php
Constructing URL: Proper Query Parameter Encoding
September 3, 2025 - Write a Python program that constructs a URL with query parameters and ensures that the URL is encoded correctly. ... # Import the urllib3 library import urllib3 # Define the base URL without query parameters base_url = 'https://example.com/api' ...
🌐
CodeRivers
coderivers.org › blog › python-urllib-encode
Python `urllib` Encode: A Comprehensive Guide - CodeRivers
January 29, 2025 - To encode a query string in Python using urllib, you can use the urllib.parse.urlencode() function.
🌐
Python
docs.python.org › 3.0 › library › urllib.parse.html
urllib.parse — Parse URLs into components — Python v3.0.1 documentation
Use the urllib.parse.urlencode() function to convert such lists of pairs into query strings.
🌐
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…
🌐
Bentasker
snippets.bentasker.co.uk › posts › python3 › lowercase-url-encoding-with-urllib-in-python3.html
Lowercase URL Encoding with Urllib in Python3 (Python3) | snippets.bentasker.co.uk
September 9, 2020 - import re import urllib.parse def quote_url_lower(url,safe='/'): s=urllib.parse.quote(url,safe) pattern = "%[A-Z,0-9][A-Z,0-9]" # Convert the result to a set so each entry is unique result = set(re.findall(pattern,s)) for r in result: s = s.replace(r,r.lower()) return s
Published   Sep 09, 2020
Author   Ben Tasker
🌐
URLDecoder
urldecoder.io › python
URL Decoding query strings or form parameters in Python | URLDecoder
In Python 3+, You can URL decode any string using the unquote() function provided by urllib.parse package.
🌐
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.