1 # -*- coding: utf-8 -*-
7 This module contains the set of Requests' exceptions.
10 from .packages.urllib3.exceptions import HTTPError as BaseHTTPError
13 class RequestException(IOError):
14 """There was an ambiguous exception that occurred while handling your
17 def __init__(self, *args, **kwargs):
19 Initialize RequestException with `request` and `response` objects.
21 response = kwargs.pop('response', None)
22 self.response = response
23 self.request = kwargs.pop('request', None)
24 if (response is not None and not self.request and
25 hasattr(response, 'request')):
26 self.request = self.response.request
27 super(RequestException, self).__init__(*args, **kwargs)
30 class HTTPError(RequestException):
31 """An HTTP error occurred."""
34 class ConnectionError(RequestException):
35 """A Connection error occurred."""
38 class ProxyError(ConnectionError):
39 """A proxy error occurred."""
42 class SSLError(ConnectionError):
43 """An SSL error occurred."""
46 class Timeout(RequestException):
47 """The request timed out.
49 Catching this error will catch both
50 :exc:`~requests.exceptions.ConnectTimeout` and
51 :exc:`~requests.exceptions.ReadTimeout` errors.
55 class ConnectTimeout(ConnectionError, Timeout):
56 """The request timed out while trying to connect to the remote server.
58 Requests that produced this error are safe to retry.
62 class ReadTimeout(Timeout):
63 """The server did not send any data in the allotted amount of time."""
66 class URLRequired(RequestException):
67 """A valid URL is required to make a request."""
70 class TooManyRedirects(RequestException):
71 """Too many redirects."""
74 class MissingSchema(RequestException, ValueError):
75 """The URL schema (e.g. http or https) is missing."""
78 class InvalidSchema(RequestException, ValueError):
79 """See defaults.py for valid schemas."""
82 class InvalidURL(RequestException, ValueError):
83 """ The URL provided was somehow invalid. """
86 class ChunkedEncodingError(RequestException):
87 """The server declared chunked encoding but sent an invalid chunk."""
90 class ContentDecodingError(RequestException, BaseHTTPError):
91 """Failed to decode response content"""
94 class StreamConsumedError(RequestException, TypeError):
95 """The content for this response was already consumed"""
98 class RetryError(RequestException):
99 """Custom retries logic failed"""
105 class RequestsWarning(Warning):
106 """Base warning for Requests."""
110 class FileModeWarning(RequestsWarning, DeprecationWarning):
112 A file was opened in text mode, but Requests determined its binary length.