summaryrefslogtreecommitdiffstats
path: root/Doc/library/urllib.error.rst
blob: 7bd04b1bc466da44ae9fcfe9ceb582e9d9d02efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
:mod:`urllib.error` --- Exception classes raised by urllib.request
==================================================================

.. module:: urllib.error
   :synopsis: Exception classes raised by urllib.request.
.. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
.. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>


The :mod:`urllib.error` module defines the exception classes for exceptions
raised by :mod:`urllib.request`.  The base exception class is :exc:`URLError`.

The following exceptions are raised by :mod:`urllib.error` as appropriate:

.. exception:: URLError

   The handlers raise this exception (or derived exceptions) when they run into
   a problem.  It is a subclass of :exc:`OSError`.

   .. attribute:: reason

      The reason for this error.  It can be a message string or another
      exception instance.

   .. versionchanged:: 3.3
      :exc:`URLError` has been made a subclass of :exc:`OSError` instead
      of :exc:`IOError`.


.. exception:: HTTPError

   Though being an exception (a subclass of :exc:`URLError`), an
   :exc:`HTTPError` can also function as a non-exceptional file-like return
   value (the same thing that :func:`urlopen` returns).  This is useful when
   handling exotic HTTP errors, such as requests for authentication.

   .. attribute:: code

      An HTTP status code as defined in `RFC 2616
      <http://www.faqs.org/rfcs/rfc2616.html>`_.  This numeric value corresponds
      to a value found in the dictionary of codes as found in
      :attr:`http.server.BaseHTTPRequestHandler.responses`.

   .. attribute:: reason

      This is usually a string explaining the reason for this error.

   .. attribute:: headers

      The HTTP response headers for the HTTP request that cause the
      :exc:`HTTPError`.

      .. versionadded:: 3.4

.. exception:: ContentTooShortError(msg, content)

   This exception is raised when the :func:`urlretrieve` function detects that
   the amount of the downloaded data is less than the expected amount (given by
   the *Content-Length* header).  The :attr:`content` attribute stores the
   downloaded (and supposedly truncated) data.