| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | :mod:`urllib.error` --- Exception classes raised by urllib.request
 | 
					
						
							|  |  |  | ==================================================================
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. module:: urllib.error
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  |    :synopsis: Exception classes raised by urllib.request.
 | 
					
						
							| 
									
										
										
										
											2016-06-11 15:02:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 14:37:44 +00:00
										 |  |  | .. moduleauthor:: Jeremy Hylton <jeremy@alum.mit.edu>
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | .. sectionauthor:: Senthil Kumaran <orsenthil@gmail.com>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-11 15:02:54 -04:00
										 |  |  | **Source code:** :source:`Lib/urllib/error.py`
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | --------------
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  | The :mod:`urllib.error` module defines the exception classes for exceptions
 | 
					
						
							| 
									
										
										
										
											2011-10-12 20:10:51 +02:00
										 |  |  | raised by :mod:`urllib.request`.  The base exception class is :exc:`URLError`.
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | The following exceptions are raised by :mod:`urllib.error` as appropriate:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. exception:: URLError
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  |    The handlers raise this exception (or derived exceptions) when they run into
 | 
					
						
							| 
									
										
										
										
											2011-10-12 20:10:51 +02:00
										 |  |  |    a problem.  It is a subclass of :exc:`OSError`.
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    .. attribute:: reason
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  |       The reason for this error.  It can be a message string or another
 | 
					
						
							| 
									
										
										
										
											2011-10-12 20:10:51 +02:00
										 |  |  |       exception instance.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    .. versionchanged:: 3.3
 | 
					
						
							|  |  |  |       :exc:`URLError` has been made a subclass of :exc:`OSError` instead
 | 
					
						
							|  |  |  |       of :exc:`IOError`.
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. exception:: HTTPError
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  |    Though being an exception (a subclass of :exc:`URLError`), an
 | 
					
						
							|  |  |  |    :exc:`HTTPError` can also function as a non-exceptional file-like return
 | 
					
						
							| 
									
										
										
										
											2013-10-13 20:06:50 +03:00
										 |  |  |    value (the same thing that :func:`~urllib.request.urlopen` returns).  This
 | 
					
						
							|  |  |  |    is useful when handling exotic HTTP errors, such as requests for
 | 
					
						
							|  |  |  |    authentication.
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    .. attribute:: code
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-31 07:39:00 +03:00
										 |  |  |       An HTTP status code as defined in :rfc:`2616`.  This numeric value corresponds
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  |       to a value found in the dictionary of codes as found in
 | 
					
						
							|  |  |  |       :attr:`http.server.BaseHTTPRequestHandler.responses`.
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-09 13:51:05 -08:00
										 |  |  |    .. attribute:: reason
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       This is usually a string explaining the reason for this error.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-10 02:09:35 -08:00
										 |  |  |    .. attribute:: headers
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 11:33:29 -04:00
										 |  |  |       The HTTP response headers for the HTTP request that caused the
 | 
					
						
							| 
									
										
										
										
											2012-12-10 02:09:35 -08:00
										 |  |  |       :exc:`HTTPError`.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       .. versionadded:: 3.4
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 15:58:14 +00:00
										 |  |  | .. exception:: ContentTooShortError(msg, content)
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-13 20:06:50 +03:00
										 |  |  |    This exception is raised when the :func:`~urllib.request.urlretrieve`
 | 
					
						
							|  |  |  |    function detects that
 | 
					
						
							| 
									
										
										
										
											2008-06-23 11:23:31 +00:00
										 |  |  |    the amount of the downloaded data is less than the expected amount (given by
 | 
					
						
							|  |  |  |    the *Content-Length* header).  The :attr:`content` attribute stores the
 | 
					
						
							|  |  |  |    downloaded (and supposedly truncated) data.
 | 
					
						
							| 
									
										
										
										
											2008-06-23 04:41:59 +00:00
										 |  |  | 
 |