1:mod:`urllib.error` --- Exception classes raised by urllib.request
2==================================================================
3
4.. module:: urllib.error
5   :synopsis: Exception classes raised by urllib.request.
6
7.. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
8.. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>
9
10**Source code:** :source:`Lib/urllib/error.py`
11
12--------------
13
14The :mod:`urllib.error` module defines the exception classes for exceptions
15raised by :mod:`urllib.request`.  The base exception class is :exc:`URLError`.
16
17The following exceptions are raised by :mod:`urllib.error` as appropriate:
18
19.. exception:: URLError
20
21   The handlers raise this exception (or derived exceptions) when they run into
22   a problem.  It is a subclass of :exc:`OSError`.
23
24   .. attribute:: reason
25
26      The reason for this error.  It can be a message string or another
27      exception instance.
28
29   .. versionchanged:: 3.3
30      :exc:`URLError` has been made a subclass of :exc:`OSError` instead
31      of :exc:`IOError`.
32
33
34.. exception:: HTTPError
35
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
40   authentication.
41
42   .. attribute:: code
43
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`.
48
49   .. attribute:: reason
50
51      This is usually a string explaining the reason for this error.
52
53   .. attribute:: headers
54
55      The HTTP response headers for the HTTP request that caused the
56      :exc:`HTTPError`.
57
58      .. versionadded:: 3.4
59
60.. exception:: ContentTooShortError(msg, content)
61
62   This exception is raised when the :func:`~urllib.request.urlretrieve`
63   function detects that
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.
67
68