To simply encode fields in a URL, you can use urllib.urlencode.

In Python 2, this should do the trick:

import urllib
s = "https://scholar.google.com/scholar?" + urllib.urlencode({"q":"rudra banerjee"})
print(s)
# Prints: https://scholar.google.com/scholar?q=rudra+banerjee

In Python 3, it lives under urllib.parse.urlencode instead.

Answer from shazow on Stack Overflow
🌐
urllib3
urllib3.readthedocs.io › en › stable › user-guide.html
User Guide - urllib3 2.7.0 documentation
+ encoded_args resp = ... body of a request, provide the data in the json argument to request() and urllib3 will automatically encode the data using the json module with UTF-8 encoding....
🌐
Python
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components — Python 3.14.6 ...
Use the urllib.parse.urlencode() function to convert such lists of pairs into query strings.
🌐
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')}")
🌐
w3resource
w3resource.com › python-exercises › urllib3 › python-urllib3-exercise-11.php
Constructing URL: Proper Query Parameter Encoding
September 3, 2025 - # 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}")
🌐
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 ...
🌐
urllib3
urllib3.readthedocs.io › en › latest › user-guide.html
User Guide - urllib3 2.6.4.dev31 documentation
+ encoded_args resp = ... body of a request, provide the data in the json argument to request() and urllib3 will automatically encode the data using the json module with UTF-8 encoding....
🌐
WebScraping.AI
webscraping.ai › faq › urllib3 › what-is-the-role-of-request-encodings-in-urllib3-and-how-do-i-use-them
What is the role of request encodings in urllib3 and how do I use them? | WebScraping.AI
import urllib3 from urllib.parse import urlencode http = urllib3.PoolManager() # Data to be sent in the form form_data = { 'key1': 'value1', 'key2': 'value2' } # Encode the form data encoded_data = urlencode(form_data) # Make the request response = http.request( 'POST', 'http://httpbin.org/post', headers={ 'Content-Type': 'application/x-www-form-urlencoded' }, body=encoded_data ) print(response.data)
🌐
Mo4tech
mo4tech.com › home › python3 > urllib3 > urlencode
Python3 > urllib3 > urlencode - Moment For Technology
October 24, 2021 - Urllib is almost a set of urllib and urllib2 modules in Python2, so urllib is the most commonly used module and URllib3 is used as an extension module. ... from urllib import request from urllib import parse from urllib.request import urlopen values = {'username': '[email protected]', 'password': Data = parse.urlencode(values).encode('utf-8') Need for byte type url = 'https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn' request = request.Request(url, data) response = urlopen(request) print(response.read().decode())Copy the code
Find elsewhere
🌐
GitHub
github.com › urllib3 › urllib3 › blob › main › docs › user-guide.rst
urllib3/docs/user-guide.rst at main · urllib3/urllib3
+ encoded_args resp = ... to :meth:`~urllib3.PoolManager.request` and urllib3 will automatically encode the data using the json module with UTF-8 encoding....
Author   urllib3
🌐
Google
googleapis.dev › python › google-auth › 1.11.1 › _modules › urllib3 › request.html
urllib3.request — google-auth 1.11.1 documentation
""" if headers is None: headers = self.headers extra_kw = {"headers": headers} extra_kw.update(urlopen_kw) if fields: url += "?" + urlencode(fields) return self.urlopen(method, url, **extra_kw) def request_encode_body( self, method, url, fields=None, headers=None, encode_multipart=True, multipart_boundary=None, **urlopen_kw ): """ Make a request using :meth:`urlopen` with the ``fields`` encoded in the body. This is useful for request methods like POST, PUT, PATCH, etc. When ``encode_multipart=True`` (default), then :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode the payload with the appropriate content type.
🌐
ProxiesAPI
proxiesapi.com › articles › encoding-urls-with-python-s-urllib
Encoding URLs with Python's urllib | ProxiesAPI
February 6, 2024 - urllib.parse.urlencode() function takes a dictionary and converts it into a url encoded string that can be appended to URLs.
🌐
urllib3
urllib3.readthedocs.io › en › 1.26.1 › user-guide.html
User Guide - urllib3 1.26.1 documentation
+ encoded_args >>> r = http.request('POST', url) >>> json.loads(r.data.decode('utf-8'))['args'] {'arg': 'value'} For PUT and POST requests, urllib3 will automatically form-encode the dictionary in the fields argument provided to request(): >>> r = http.request( ...
🌐
URL Encoder
urlencoder.io › python
How to encode URLs in Python | URLEncoder
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.
🌐
GitHub
github.com › urllib3 › urllib3 › issues › 952
urllib3 does not urlencode redirect targets on redirect. · Issue #952 · urllib3/urllib3
August 18, 2016 - urllib3 does not urlencode redirect targets on redirect.#952 · #1487 · Copy link · Assignees · eladbitton · opened · on Aug 18, 2016 · Issue body actions · I am crawling pages and I'm getting UnicodeEncodeError.
Author   urllib3
🌐
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.
🌐
Delft Stack
delftstack.com › home › howto › python › python urlencode
How to Use Urlencode in Python | Delft Stack
February 15, 2024 - Whenever we call a web API or submit an HTTP form data, we use an encoded URL to encode the query string. 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.
🌐
urllib3
urllib3.readthedocs.io › en › 1.26.4 › user-guide.html
User Guide - urllib3 1.26.4 documentation
+ encoded_args >>> r = http.request('POST', url) >>> json.loads(r.data.decode('utf-8'))['args'] {'arg': 'value'} For PUT and POST requests, urllib3 will automatically form-encode the dictionary in the fields argument provided to request(): >>> r = http.request( ...