Home

urllibparsequote

urllib.parse.quote is a function in Python’s standard library module urllib.parse that percent-encodes a string for safe inclusion in a URL. It converts characters outside an allowed set into their %XX hexadecimal representations, ensuring the resulting string can be transmitted in a URL without misinterpretation.

The function signature is quote(string, safe='/', encoding='utf-8', errors='strict'). The safe parameter specifies characters that should not

Common usage includes constructing query or path components from user input. For example, quote("caf\xc3\xa9") returns 'caf%C3%A9'

Examples:

- from urllib.parse import quote; quote("[email protected]") -> 'email%40example.com'

- quote("café", encoding="utf-8") -> 'caf%C3%A9'

- quote("path with spaces/", safe="/") -> 'path%20with%20spaces/'

See also: quote_plus, unquote, unquote_plus, urlencode, and the urllib.parse module documentation.

be
encoded,
with
'/'
commonly
allowed
to
keep
URL
path
components
intact.
The
encoding
and
errors
parameters
control
how
the
input
string
is
converted
to
bytes
before
percent-encoding;
by
default
encoding
is
'utf-8'
and
errors
is
'strict',
so
non-ASCII
characters
are
encoded
using
UTF-8
and
any
encoding
errors
raise
an
exception.
when
using
the
default
UTF-8
encoding.
If
you
are
building
a
query
string
and
want
spaces
encoded
as
plus
signs
instead
of
%20,
you
should
use
quote_plus,
which
is
a
related
function.