Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame^] | 1 | :mod:`urllib.error` --- Exception classes raised by urllib.request |
| 2 | ================================================================== |
| 3 | |
| 4 | .. module:: urllib.error |
| 5 | :synopsis: Next generation URL opening library. |
| 6 | .. moduleauthor:: Jeremy Hylton <jhylton@users.sourceforge.net> |
| 7 | .. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com> |
| 8 | |
| 9 | |
| 10 | The :mod:`urllib.error` module defines exception classes raise by |
| 11 | urllib.request. The base exception class is URLError, which inherits from |
| 12 | IOError. |
| 13 | |
| 14 | The following exceptions are raised by :mod:`urllib.error` as appropriate: |
| 15 | |
| 16 | |
| 17 | .. exception:: URLError |
| 18 | |
| 19 | The handlers raise this exception (or derived exceptions) when they run into a |
| 20 | problem. It is a subclass of :exc:`IOError`. |
| 21 | |
| 22 | .. attribute:: reason |
| 23 | |
| 24 | The reason for this error. It can be a message string or another exception |
| 25 | instance (:exc:`socket.error` for remote URLs, :exc:`OSError` for local |
| 26 | URLs). |
| 27 | |
| 28 | |
| 29 | .. exception:: HTTPError |
| 30 | |
| 31 | Though being an exception (a subclass of :exc:`URLError`), an :exc:`HTTPError` |
| 32 | can also function as a non-exceptional file-like return value (the same thing |
| 33 | that :func:`urlopen` returns). This is useful when handling exotic HTTP |
| 34 | errors, such as requests for authentication. |
| 35 | |
| 36 | .. attribute:: code |
| 37 | |
| 38 | An HTTP status code as defined in `RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html>`_. |
| 39 | This numeric value corresponds to a value found in the dictionary of |
| 40 | codes as found in :attr:`http.server.BaseHTTPRequestHandler.responses`. |
| 41 | |
| 42 | .. exception:: ContentTooShortError(msg[, content]) |
| 43 | |
| 44 | This exception is raised when the :func:`urlretrieve` function detects that the |
| 45 | amount of the downloaded data is less than the expected amount (given by the |
| 46 | *Content-Length* header). The :attr:`content` attribute stores the downloaded |
| 47 | (and supposedly truncated) data. |
| 48 | |