blob: 793d3e2b1a3a1aec63a65be149f8b1e8342cb39f [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
11raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`,
12which inherits from :exc:`IOError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000013
14The following exceptions are raised by :mod:`urllib.error` as appropriate:
15
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000016.. exception:: URLError
17
Georg Brandl0f7ede42008-06-23 11:23:31 +000018 The handlers raise this exception (or derived exceptions) when they run into
19 a problem. It is a subclass of :exc:`IOError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000020
21 .. attribute:: reason
22
Georg Brandl0f7ede42008-06-23 11:23:31 +000023 The reason for this error. It can be a message string or another
Antoine Pitrou5574c302011-10-12 17:53:43 +020024 exception instance such as :exc:`OSError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000025
26
27.. exception:: HTTPError
28
Georg Brandl0f7ede42008-06-23 11:23:31 +000029 Though being an exception (a subclass of :exc:`URLError`), an
30 :exc:`HTTPError` can also function as a non-exceptional file-like return
31 value (the same thing that :func:`urlopen` returns). This is useful when
32 handling exotic HTTP errors, such as requests for authentication.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000033
34 .. attribute:: code
35
Georg Brandl0f7ede42008-06-23 11:23:31 +000036 An HTTP status code as defined in `RFC 2616
37 <http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds
38 to a value found in the dictionary of codes as found in
39 :attr:`http.server.BaseHTTPRequestHandler.responses`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000040
Georg Brandl7f01a132009-09-16 15:58:14 +000041.. exception:: ContentTooShortError(msg, content)
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000042
Georg Brandl0f7ede42008-06-23 11:23:31 +000043 This exception is raised when the :func:`urlretrieve` function detects that
44 the amount of the downloaded data is less than the expected amount (given by
45 the *Content-Length* header). The :attr:`content` attribute stores the
46 downloaded (and supposedly truncated) data.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000047