Python Glossary Русский

Python 3.2+urllib.parseterm

urllib.parse.ParseResultBytes

parse results

The result of urlparse() for bytes: the same six fields as ParseResult, but the fields are byte strings.

Syntax

ParseResultBytes(scheme, netloc, path, params, query, fragment)

You get it when urlparse() receives bytes, for example data read from a socket. decode() uses ASCII by default and fails on other bytes, so a byte URL with non-ASCII characters needs an explicit decode('utf-8'). Comparing with a str (r.scheme == 'http') silently gives False.

Examples

from urllib.parse import urlparse
r = urlparse(b'http://h/p?q=1')
print(type(r).__name__, r.scheme == 'http')  # → ParseResultBytes False
print(r.decode().query)  # → q=1

See also

Open in the full glossarydocs.python.orgReport an inaccuracy