Networking and Internet Modules

urllib.response

Response wrapper classes used by URL handlers. addinfourl combines a file-like body with headers, URL and optional status. Close responses to release resources; reading bytes and decoding text are separate operations.

Formal Syntax & Structure

python syntaxpython
import urllib.response

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from urllib.response import addinfourlfrom io import BytesIOwith addinfourl(BytesIO(b"ok"), {}, "https://example.invalid", 200) as response:    print(response.status, response.read().decode())
Python Reference