1
:mod:`urllib.error` --- Exception classes raised by urllib.request
2
==================================================================
4
.. module:: urllib.error
5
:synopsis: Exception classes raised by urllib.request.
7
.. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
8
.. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>
10
**Source code:** :source:`Lib/urllib/error.py`
14
The :mod:`urllib.error` module defines the exception classes for exceptions
15
raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`.
17
The following exceptions are raised by :mod:`urllib.error` as appropriate:
19
.. exception:: URLError
21
The handlers raise this exception (or derived exceptions) when they run into
22
a problem. It is a subclass of :exc:`OSError`.
26
The reason for this error. It can be a message string or another
29
.. versionchanged:: 3.3
30
:exc:`URLError` has been made a subclass of :exc:`OSError` instead
34
.. exception:: HTTPError
36
Though being an exception (a subclass of :exc:`URLError`), an
37
:exc:`HTTPError` can also function as a non-exceptional file-like return
38
value (the same thing that :func:`~urllib.request.urlopen` returns). This
39
is useful when handling exotic HTTP errors, such as requests for
44
An HTTP status code as defined in `RFC 2616
45
<http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds
46
to a value found in the dictionary of codes as found in
47
:attr:`http.server.BaseHTTPRequestHandler.responses`.
51
This is usually a string explaining the reason for this error.
53
.. attribute:: headers
55
The HTTP response headers for the HTTP request that caused the
60
.. exception:: ContentTooShortError(msg, content)
62
This exception is raised when the :func:`~urllib.request.urlretrieve`
64
the amount of the downloaded data is less than the expected amount (given by
65
the *Content-Length* header). The :attr:`content` attribute stores the
66
downloaded (and supposedly truncated) data.