urllib.error — Exception classes raised by urllib.request¶
Source code:Lib/urllib/error.py
Theurllib.error module defines the exception classes for exceptionsraised byurllib.request. The base exception class isURLError.
The following exceptions are raised byurllib.error as appropriate:
- exception
urllib.error.URLError¶ The handlers raise this exception (or derived exceptions) when they run intoa problem. It is a subclass of
OSError.reason¶The reason for this error. It can be a message string or anotherexception instance.
- exception
urllib.error.HTTPError¶ Though being an exception (a subclass of
URLError), anHTTPErrorcan also function as a non-exceptional file-like returnvalue (the same thing thaturlopen()returns). Thisis useful when handling exotic HTTP errors, such as requests forauthentication.code¶An HTTP status code as defined inRFC 2616. This numeric value correspondsto a value found in the dictionary of codes as found in
http.server.BaseHTTPRequestHandler.responses.
reason¶This is usually a string explaining the reason for this error.
- exception
urllib.error.ContentTooShortError(msg,content)¶ This exception is raised when the
urlretrieve()function detects thatthe amount of the downloaded data is less than the expected amount (given bytheContent-Length header). Thecontentattribute stores thedownloaded (and supposedly truncated) data.