:mod:`!urllib.error` --- Exception classes raised by urllib.request
Python 3.14 Docs · نسخهٔ 3.14.10 · PSF License
:mod:!urllib.error --- Exception classes raised by urllib.request
:synopsis: Exception classes raised by urllib.request.
Source code: Lib/urllib/error.py
--------------
The !urllib.error module defines the exception classes for exceptions raised by urllib.request. The base exception class is URLError.
The following exceptions are raised by !urllib.error as appropriate:
The handlers raise this exception (or derived exceptions) when they run into a problem. It is a subclass of OSError.
The reason for this error. It can be a message string or another exception instance.
URLError used to be a subtype of IOError, which is now an alias of OSError.
Though being an exception (a subclass of URLError), an HTTPError can also function as a non-exceptional file-like return value (the same thing that ~urllib.request.urlopen returns). This is useful when handling exotic HTTP errors, such as requests for authentication.
Contains the request URL. An alias for *filename* attribute.
An HTTP status code as defined in 2616. This numeric value corresponds to a value found in the dictionary of codes as found in http.server.BaseHTTPRequestHandler.responses.
This is usually a string explaining the reason for this error. An alias for *msg* attribute.
The HTTP response headers for the HTTP request that caused the HTTPError. An alias for *hdrs* attribute.
A file-like object where the HTTP error body can be read from.
This exception is raised when the ~urllib.request.urlretrieve function detects that the amount of the downloaded data is less than the expected amount (given by the *Content-Length* header).
The downloaded (and supposedly truncated) data.