blob: f7f0c9739d8c93a44bb60f5b38aa50f3ecf05e70 [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
Serhiy Storchaka5e1c0532013-10-13 20:06:50 +030034 value (the same thing that :func:`~urllib.request.urlopen` returns). This
35 is useful when handling exotic HTTP errors, such as requests for
36 authentication.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000037
38 .. attribute:: code
39
Georg Brandl0f7ede42008-06-23 11:23:31 +000040 An HTTP status code as defined in `RFC 2616
41 <http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds
42 to a value found in the dictionary of codes as found in
43 :attr:`http.server.BaseHTTPRequestHandler.responses`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000044
Senthil Kumaran2e728312012-12-09 13:51:05 -080045 .. attribute:: reason
46
47 This is usually a string explaining the reason for this error.
48
Senthil Kumaran5962cce2012-12-10 02:09:35 -080049 .. attribute:: headers
50
Larry Hastings3732ed22014-03-15 21:13:56 -070051 The HTTP response headers for the HTTP request that caused the
Senthil Kumaran5962cce2012-12-10 02:09:35 -080052 :exc:`HTTPError`.
53
54 .. versionadded:: 3.4
55
Georg Brandl7f01a132009-09-16 15:58:14 +000056.. exception:: ContentTooShortError(msg, content)
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000057
Serhiy Storchaka5e1c0532013-10-13 20:06:50 +030058 This exception is raised when the :func:`~urllib.request.urlretrieve`
59 function detects that
Georg Brandl0f7ede42008-06-23 11:23:31 +000060 the amount of the downloaded data is less than the expected amount (given by
61 the *Content-Length* header). The :attr:`content` attribute stores the
62 downloaded (and supposedly truncated) data.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000063