urllib.error
— 由 urllib.request 引发的异常类
¶
源代码: Lib/urllib/error.py
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.
3.3 版改变:
URLError
has been made a subclass of
OSError
而不是
IOError
.
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
urlopen()
returns). This is useful when handling exotic HTTP errors, such as requests for authentication.
An HTTP status code as defined in
RFC 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.
此异常被引发当
urlretrieve()
function detects that the amount of the downloaded data is less than the expected amount (given by the
Content-Length
header). The
content
attribute stores the downloaded (and supposedly truncated) data.