blob: f7d47ed76aca18fbbbbac3e064647c39972b4d5a [file] [log] [blame]
Senthil Kumaranaca8fd72008-06-23 04:41:59 +00001:mod:`urllib.error` --- Exception classes raised by urllib.request
2==================================================================
3
4.. module:: urllib.error
Georg Brandl0f7ede42008-06-23 11:23:31 +00005 :synopsis: Exception classes raised by urllib.request.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Jeremy Hyltonabb02fd2009-03-31 14:37:44 +00007.. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
Senthil Kumaranaca8fd72008-06-23 04:41:59 +00008.. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>
9
Terry Jan Reedyfa089b92016-06-11 15:02:54 -040010**Source code:** :source:`Lib/urllib/error.py`
11
12--------------
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000013
Georg Brandl0f7ede42008-06-23 11:23:31 +000014The :mod:`urllib.error` module defines the exception classes for exceptions
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020015raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000016
17The following exceptions are raised by :mod:`urllib.error` as appropriate:
18
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000019.. exception:: URLError
20
Georg Brandl0f7ede42008-06-23 11:23:31 +000021 The handlers raise this exception (or derived exceptions) when they run into
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020022 a problem. It is a subclass of :exc:`OSError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000023
24 .. attribute:: reason
25
Georg Brandl0f7ede42008-06-23 11:23:31 +000026 The reason for this error. It can be a message string or another
Antoine Pitrou62ab10a02011-10-12 20:10:51 +020027 exception instance.
28
29 .. versionchanged:: 3.3
30 :exc:`URLError` has been made a subclass of :exc:`OSError` instead
31 of :exc:`IOError`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000032
33
34.. exception:: HTTPError
35
Georg Brandl0f7ede42008-06-23 11:23:31 +000036 Though being an exception (a subclass of :exc:`URLError`), an
37 :exc:`HTTPError` can also function as a non-exceptional file-like return
Serhiy Storchaka5e1c0532013-10-13 20:06:50 +030038 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 Kumaranaca8fd72008-06-23 04:41:59 +000041
42 .. attribute:: code
43
Serhiy Storchaka0a36ac12018-05-31 07:39:00 +030044 An HTTP status code as defined in :rfc:`2616`. This numeric value corresponds
Georg Brandl0f7ede42008-06-23 11:23:31 +000045 to a value found in the dictionary of codes as found in
46 :attr:`http.server.BaseHTTPRequestHandler.responses`.
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000047
Senthil Kumaran2e728312012-12-09 13:51:05 -080048 .. attribute:: reason
49
50 This is usually a string explaining the reason for this error.
51
Senthil Kumaran5962cce2012-12-10 02:09:35 -080052 .. attribute:: headers
53
R David Murrayb8955052014-03-13 11:33:29 -040054 The HTTP response headers for the HTTP request that caused the
Senthil Kumaran5962cce2012-12-10 02:09:35 -080055 :exc:`HTTPError`.
56
57 .. versionadded:: 3.4
58
Georg Brandl7f01a132009-09-16 15:58:14 +000059.. exception:: ContentTooShortError(msg, content)
Senthil Kumaranaca8fd72008-06-23 04:41:59 +000060
Serhiy Storchaka5e1c0532013-10-13 20:06:50 +030061 This exception is raised when the :func:`~urllib.request.urlretrieve`
62 function detects that
Georg Brandl0f7ede42008-06-23 11:23:31 +000063 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 Kumaranaca8fd72008-06-23 04:41:59 +000066