| 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. | 
| Jeremy Hylton | abb02fd | 2009-03-31 14:37:44 +0000 | [diff] [blame] | 6 | .. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu> | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 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 | 
| Antoine Pitrou | 62ab10a0 | 2011-10-12 20:10:51 +0200 | [diff] [blame] | 11 | raised by :mod:`urllib.request`.  The base exception class is :exc:`URLError`. | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 12 |  | 
 | 13 | The following exceptions are raised by :mod:`urllib.error` as appropriate: | 
 | 14 |  | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 15 | .. exception:: URLError | 
 | 16 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 17 |    The handlers raise this exception (or derived exceptions) when they run into | 
| Antoine Pitrou | 62ab10a0 | 2011-10-12 20:10:51 +0200 | [diff] [blame] | 18 |    a problem.  It is a subclass of :exc:`OSError`. | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 19 |  | 
 | 20 |    .. attribute:: reason | 
 | 21 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 22 |       The reason for this error.  It can be a message string or another | 
| Antoine Pitrou | 62ab10a0 | 2011-10-12 20:10:51 +0200 | [diff] [blame] | 23 |       exception instance. | 
 | 24 |  | 
 | 25 |    .. versionchanged:: 3.3 | 
 | 26 |       :exc:`URLError` has been made a subclass of :exc:`OSError` instead | 
 | 27 |       of :exc:`IOError`. | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 28 |  | 
 | 29 |  | 
 | 30 | .. exception:: HTTPError | 
 | 31 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 32 |    Though being an exception (a subclass of :exc:`URLError`), an | 
 | 33 |    :exc:`HTTPError` can also function as a non-exceptional file-like return | 
| Serhiy Storchaka | 5e1c053 | 2013-10-13 20:06:50 +0300 | [diff] [blame] | 34 |    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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 37 |  | 
 | 38 |    .. attribute:: code | 
 | 39 |  | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 40 |       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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 44 |  | 
| Senthil Kumaran | 2e72831 | 2012-12-09 13:51:05 -0800 | [diff] [blame] | 45 |    .. attribute:: reason | 
 | 46 |  | 
 | 47 |       This is usually a string explaining the reason for this error. | 
 | 48 |  | 
| Senthil Kumaran | 5962cce | 2012-12-10 02:09:35 -0800 | [diff] [blame] | 49 |    .. attribute:: headers | 
 | 50 |  | 
| R David Murray | b895505 | 2014-03-13 11:33:29 -0400 | [diff] [blame] | 51 |       The HTTP response headers for the HTTP request that caused the | 
| Senthil Kumaran | 5962cce | 2012-12-10 02:09:35 -0800 | [diff] [blame] | 52 |       :exc:`HTTPError`. | 
 | 53 |  | 
 | 54 |       .. versionadded:: 3.4 | 
 | 55 |  | 
| Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 56 | .. exception:: ContentTooShortError(msg, content) | 
| Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 57 |  | 
| Serhiy Storchaka | 5e1c053 | 2013-10-13 20:06:50 +0300 | [diff] [blame] | 58 |    This exception is raised when the :func:`~urllib.request.urlretrieve` | 
 | 59 |    function detects that | 
| Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 60 |    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 Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 63 |  |