urllib.error --- urllib.request 引发的异常类¶
源代码: Lib/urllib/error.py
The urllib.error module defines the exception classes for exceptions
raised by urllib.request. The base exception class is URLError.
下列异常会被 urllib.error 按需引发:
-
exception
urllib.error.URLError¶ The handlers raise this exception (or derived exceptions) when they run into a problem. It is a subclass of
OSError.-
reason¶ The reason for this error. It can be a message string or another exception instance.
-
-
exception
urllib.error.HTTPError¶ Though being an exception (a subclass of
URLError), anHTTPErrorcan also function as a non-exceptional file-like return value (the same thing thaturlopen()returns). This is useful when handling exotic HTTP errors, such as requests for authentication.-
code¶ 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.
-
reason¶ 这通常是一个解释本次错误原因的字符串。
-
-
exception
urllib.error.ContentTooShortError(msg, content)¶ This exception is raised when the
urlretrieve()function detects that the amount of the downloaded data is less than the expected amount (given by the Content-Length header). Thecontentattribute stores the downloaded (and supposedly truncated) data.
