| 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 | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 5 |    :synopsis: Exception classes raised by urllib.request. | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 6 | .. moduleauthor:: Jeremy Hylton <jhylton@users.sourceforge.net> | 
 | 7 | .. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com> | 
 | 8 |  | 
 | 9 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 10 | The :mod:`urllib.error` module defines the exception classes for exceptions | 
 | 11 | raised by :mod:`urllib.request`.  The base exception class is :exc:`URLError`, | 
 | 12 | which inherits from :exc:`IOError`. | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 13 |  | 
 | 14 | The following exceptions are raised by :mod:`urllib.error` as appropriate: | 
 | 15 |  | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 16 | .. exception:: URLError | 
 | 17 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 18 |    The handlers raise this exception (or derived exceptions) when they run into | 
 | 19 |    a problem.  It is a subclass of :exc:`IOError`. | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 20 |  | 
 | 21 |    .. attribute:: reason | 
 | 22 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 23 |       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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 26 |  | 
 | 27 |  | 
 | 28 | .. exception:: HTTPError | 
 | 29 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 30 |    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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 34 |  | 
 | 35 |    .. attribute:: code | 
 | 36 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 37 |       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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 41 |  | 
 | 42 | .. exception:: ContentTooShortError(msg[, content]) | 
 | 43 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 44 |    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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 48 |  |