blob: 9c3fe91118a667066842353a3408eef41adbf5c5 [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.
Jeremy Hyltonabb02fd2009-03-31 14:37:44 +00006.. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
Senthil Kumaranaca8fd72008-06-23 04:41:59 +00007.. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>
8
9
Georg Brandl0f7ede42008-06-23 11:23:31 +000010The :mod:`urllib.error` module defines the exception classes for exceptions
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020011raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000012
13The following exceptions are raised by :mod:`urllib.error` as appropriate:
14
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000015.. exception:: URLError
16
Georg Brandl0f7ede42008-06-23 11:23:31 +000017 The handlers raise this exception (or derived exceptions) when they run into
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020018 a problem. It is a subclass of :exc:`OSError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000019
20 .. attribute:: reason
21
Georg Brandl0f7ede42008-06-23 11:23:31 +000022 The reason for this error. It can be a message string or another
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020023 exception instance.
24
25 .. versionchanged:: 3.3
26 :exc:`URLError` has been made a subclass of :exc:`OSError` instead
27 of :exc:`IOError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000028
29
30.. exception:: HTTPError
31
Georg Brandl0f7ede42008-06-23 11:23:31 +000032 Though being an exception (a subclass of :exc:`URLError`), an
33 :exc:`HTTPError` can also function as a non-exceptional file-like return
34 value (the same thing that :func:`urlopen` returns). This is useful when
35 handling exotic HTTP errors, such as requests for authentication.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000036
37 .. attribute:: code
38
Georg Brandl0f7ede42008-06-23 11:23:31 +000039 An HTTP status code as defined in `RFC 2616
40 <http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds
41 to a value found in the dictionary of codes as found in
42 :attr:`http.server.BaseHTTPRequestHandler.responses`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000043
Senthil Kumaran2e728312012-12-09 13:51:05 -080044 .. attribute:: reason
45
46 This is usually a string explaining the reason for this error.
47
Georg Brandl7f01a132009-09-16 15:58:14 +000048.. exception:: ContentTooShortError(msg, content)
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000049
Georg Brandl0f7ede42008-06-23 11:23:31 +000050 This exception is raised when the :func:`urlretrieve` function detects that
51 the amount of the downloaded data is less than the expected amount (given by
52 the *Content-Length* header). The :attr:`content` attribute stores the
53 downloaded (and supposedly truncated) data.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000054