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. |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | |
Jeremy Hylton | abb02fd | 2009-03-31 14:37:44 +0000 | [diff] [blame] | 7 | .. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu> |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 8 | .. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com> |
| 9 | |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 10 | **Source code:** :source:`Lib/urllib/error.py` |
| 11 | |
| 12 | -------------- |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 13 | |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 14 | The :mod:`urllib.error` module defines the exception classes for exceptions |
Antoine Pitrou | 62ab10a0 | 2011-10-12 20:10:51 +0200 | [diff] [blame] | 15 | raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 16 | |
| 17 | The following exceptions are raised by :mod:`urllib.error` as appropriate: |
| 18 | |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 19 | .. exception:: URLError |
| 20 | |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 21 | The handlers raise this exception (or derived exceptions) when they run into |
Antoine Pitrou | 62ab10a0 | 2011-10-12 20:10:51 +0200 | [diff] [blame] | 22 | a problem. It is a subclass of :exc:`OSError`. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 23 | |
| 24 | .. attribute:: reason |
| 25 | |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 26 | 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] | 27 | exception instance. |
| 28 | |
| 29 | .. versionchanged:: 3.3 |
| 30 | :exc:`URLError` has been made a subclass of :exc:`OSError` instead |
| 31 | of :exc:`IOError`. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 32 | |
| 33 | |
| 34 | .. exception:: HTTPError |
| 35 | |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 36 | Though being an exception (a subclass of :exc:`URLError`), an |
| 37 | :exc:`HTTPError` can also function as a non-exceptional file-like return |
Serhiy Storchaka | 5e1c053 | 2013-10-13 20:06:50 +0300 | [diff] [blame] | 38 | value (the same thing that :func:`~urllib.request.urlopen` returns). This |
| 39 | is useful when handling exotic HTTP errors, such as requests for |
| 40 | authentication. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 41 | |
| 42 | .. attribute:: code |
| 43 | |
Serhiy Storchaka | 0a36ac1 | 2018-05-31 07:39:00 +0300 | [diff] [blame] | 44 | An HTTP status code as defined in :rfc:`2616`. This numeric value corresponds |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 45 | to a value found in the dictionary of codes as found in |
| 46 | :attr:`http.server.BaseHTTPRequestHandler.responses`. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 47 | |
Senthil Kumaran | 2e72831 | 2012-12-09 13:51:05 -0800 | [diff] [blame] | 48 | .. attribute:: reason |
| 49 | |
| 50 | This is usually a string explaining the reason for this error. |
| 51 | |
Senthil Kumaran | 5962cce | 2012-12-10 02:09:35 -0800 | [diff] [blame] | 52 | .. attribute:: headers |
| 53 | |
R David Murray | b895505 | 2014-03-13 11:33:29 -0400 | [diff] [blame] | 54 | The HTTP response headers for the HTTP request that caused the |
Senthil Kumaran | 5962cce | 2012-12-10 02:09:35 -0800 | [diff] [blame] | 55 | :exc:`HTTPError`. |
| 56 | |
| 57 | .. versionadded:: 3.4 |
| 58 | |
Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 59 | .. exception:: ContentTooShortError(msg, content) |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 60 | |
Serhiy Storchaka | 5e1c053 | 2013-10-13 20:06:50 +0300 | [diff] [blame] | 61 | This exception is raised when the :func:`~urllib.request.urlretrieve` |
| 62 | function detects that |
Georg Brandl | 0f7ede4 | 2008-06-23 11:23:31 +0000 | [diff] [blame] | 63 | the amount of the downloaded data is less than the expected amount (given by |
| 64 | the *Content-Length* header). The :attr:`content` attribute stores the |
| 65 | downloaded (and supposedly truncated) data. |
Senthil Kumaran | aca8fd7 | 2008-06-23 04:41:59 +0000 | [diff] [blame] | 66 | |