all Python 3urllib.parsefunction
urllib.parse.quote()
percent-encoding
Replaces special and non-ASCII characters in a string with %XX (percent-encoding) — for putting text into a URL path.
Syntax
urllib.parse.quote(string, safe='/', encoding=None, errors=None)
The default is safe='/', so the slash is not encoded: for a file name or a parameter value where '/' is part of the data, use quote(s, safe=''). A space becomes %20, not '+' — quote_plus() is the one for HTML forms. Text is encoded to UTF-8 first, so one Cyrillic letter yields two %XX pairs.
Examples
from urllib.parse import quote
print(quote('a b/c&d')) # → a%20b/c%26d — косая черта осталась
print(quote('a/b', safe='')) # → a%2Fb
print(quote('ё')) # → %D1%91
See also
Open in the full glossarydocs.python.orgReport an inaccuracy