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 |
| 34 | value (the same thing that :func:`urlopen` returns). This is useful when |
| 35 | handling exotic HTTP errors, such as requests for authentication. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 36 | |
| 37 | .. attribute:: code |
| 38 | |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 39 | An HTTP status code as defined in `RFC 2616 |
| 40 | <http://www.faqs.org/rfcs/rfc2616.html>`_. This numeric value corresponds |
| 41 | to a value found in the dictionary of codes as found in |
| 42 | :attr:`http.server.BaseHTTPRequestHandler.responses`. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 43 | |
Senthil Kumaran | 2e72831 | 2012-12-09 13:51:05 -0800 | [diff] [blame] | 44 | .. attribute:: reason |
| 45 | |
| 46 | This is usually a string explaining the reason for this error. |
| 47 | |
Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 48 | .. exception:: ContentTooShortError(msg, content) |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 49 | |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 50 | This exception is raised when the :func:`urlretrieve` function detects that |
| 51 | the amount of the downloaded data is less than the expected amount (given by |
| 52 | the *Content-Length* header). The :attr:`content` attribute stores the |
| 53 | downloaded (and supposedly truncated) data. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 54 | |