blob: 282329fe5d718a70c6dbd8403d14a7b750e60af1 [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
24 exception instance (:exc:`socket.error` for remote URLs, :exc:`OSError`
25 for local URLs).
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000026
27
28.. exception:: HTTPError
29
Georg Brandl0f7ede42008-06-23 11:23:31 +000030 Though being an exception (a subclass of :exc:`URLError`), an
31 :exc:`HTTPError` can also function as a non-exceptional file-like return
32 value (the same thing that :func:`urlopen` returns). This is useful when
33 handling exotic HTTP errors, such as requests for authentication.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000034
35 .. attribute:: code
36
Georg Brandl0f7ede42008-06-23 11:23:31 +000037 An HTTP status code as defined in `RFC 2616
38 <http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds
39 to a value found in the dictionary of codes as found in
40 :attr:`http.server.BaseHTTPRequestHandler.responses`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000041
Georg Brandlb044b2a2009-09-16 16:05:59 +000042.. exception:: ContentTooShortError(msg, content)
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000043
Georg Brandl0f7ede42008-06-23 11:23:31 +000044 This exception is raised when the :func:`urlretrieve` function detects that
45 the amount of the downloaded data is less than the expected amount (given by
46 the *Content-Length* header). The :attr:`content` attribute stores the
47 downloaded (and supposedly truncated) data.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000048