blob: 5517b04f5ddf7145eea06e63d895740698f7bb8a [file] [log] [blame]
Senthil Kumaranaca8fd72008-06-23 04:41:59 +00001:mod:`urllib.error` --- Exception classes raised by urllib.request
2==================================================================
3
4.. module:: urllib.error
Georg Brandl0f7ede42008-06-23 11:23:31 +00005 :synopsis: Exception classes raised by urllib.request.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Jeremy Hyltonabb02fd2009-03-31 14:37:44 +00007.. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
Senthil Kumaranaca8fd72008-06-23 04:41:59 +00008.. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>
9
Terry Jan Reedyfa089b92016-06-11 15:02:54 -040010**Source code:** :source:`Lib/urllib/error.py`
11
12--------------
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000013
Georg Brandl0f7ede42008-06-23 11:23:31 +000014The :mod:`urllib.error` module defines the exception classes for exceptions
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020015raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000016
17The following exceptions are raised by :mod:`urllib.error` as appropriate:
18
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000019.. exception:: URLError
20
Georg Brandl0f7ede42008-06-23 11:23:31 +000021 The handlers raise this exception (or derived exceptions) when they run into
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020022 a problem. It is a subclass of :exc:`OSError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000023
24 .. attribute:: reason
25
Georg Brandl0f7ede42008-06-23 11:23:31 +000026 The reason for this error. It can be a message string or another
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020027 exception instance.
28
29 .. versionchanged:: 3.3
30 :exc:`URLError` has been made a subclass of :exc:`OSError` instead
31 of :exc:`IOError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000032
33
34.. exception:: HTTPError
35
Georg Brandl0f7ede42008-06-23 11:23:31 +000036 Though being an exception (a subclass of :exc:`URLError`), an
37 :exc:`HTTPError` can also function as a non-exceptional file-like return
Serhiy Storchaka5e1c0532013-10-13 20:06:50 +030038 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.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000041
42 .. attribute:: code
43
Georg Brandl0f7ede42008-06-23 11:23:31 +000044 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`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000048
Senthil Kumaran2e728312012-12-09 13:51:05 -080049 .. attribute:: reason
50
51 This is usually a string explaining the reason for this error.
52
Senthil Kumaran5962cce2012-12-10 02:09:35 -080053 .. attribute:: headers
54
R David Murrayb8955052014-03-13 11:33:29 -040055 The HTTP response headers for the HTTP request that caused the
Senthil Kumaran5962cce2012-12-10 02:09:35 -080056 :exc:`HTTPError`.
57
58 .. versionadded:: 3.4
59
Georg Brandl7f01a132009-09-16 15:58:14 +000060.. exception:: ContentTooShortError(msg, content)
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000061
Serhiy Storchaka5e1c0532013-10-13 20:06:50 +030062 This exception is raised when the :func:`~urllib.request.urlretrieve`
63 function detects that
Georg Brandl0f7ede42008-06-23 11:23:31 +000064 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.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000067