Python Glossary Русский

all Python 3urllib.parsefunction

urllib.parse.unquote()

percent-encoding

Replaces %XX sequences with the characters they stand for, decoding the bytes as UTF-8 — the inverse of quote().

Syntax

urllib.parse.unquote(string, encoding='utf-8', errors='replace')

'+' stays a plus: a string from an HTML form needs unquote_plus(). An invalid UTF-8 sequence raises no error — the default is errors='replace', and the replacement character appears instead, so data corruption goes unnoticed. Calling it twice is risky: '%2541' becomes '%41' after the first call and 'A' after the second.

Examples

from urllib.parse import unquote
print(unquote('a+b%20c'))  # → a+b c
print(unquote('%D0%BF'))  # → п
print(unquote(unquote('%2541')))  # → A — двойная расшифровка

See also

Open in the full glossarydocs.python.orgReport an inaccuracy