urllib.parse.urlencode()
urllib.parse.urlencode() is a Python function in the Urllib Module category. Encodes dictionary or sequence of pairs into a URL query string. The syntax is urllib.parse.urlencode(query, doseq=False, safe="", encoding=None, errors=None, quote_via=quote_plus). Parameters: query — dict or pairs. Returns: URL-encoded query string. A typical example: from urllib.parse import urlencode
urlencode({"search": "python reference", "page": 1})
# "search=python+reference&page=1". A close sibling is urllib.request.urlopen(), which opens a URL for reading (like GET request). Returns a file-like response object. A close sibling is urllib.request.Request(), which creates an HTTP request with custom headers and method. A close sibling is urllib.parse.urlparse(), which parses a URL into its components (scheme, netloc, path, params, query, fragment). A close sibling is urllib.parse.urljoin(), which constructs a full URL by combining a base URL with a relative URL. More about this category: URL handling — request, parse, urlopen, urlparse, urlencode, quote. Related Urllib Module entries: urllib.request.urlopen(), urllib.request.Request(), urllib.parse.urlparse(), urllib.parse.urljoin(), urllib.parse.quote(), urllib.parse.unquote().