Networking and Internet Modules
urllib.error
Defines errors raised by URL request handlers. URLError exposes a reason; HTTPError adds HTTP status and response-like access. Handle HTTPError before URLError when distinguishing HTTP failure responses from transport errors.
Formal Syntax & Structure
python syntaxpython
import urllib.errorReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from urllib.error import HTTPErrorerror = HTTPError("https://example.invalid", 404, "Missing", None, None)print(error.code, error.reason)