jpayne@7: """ jpayne@7: requests.exceptions jpayne@7: ~~~~~~~~~~~~~~~~~~~ jpayne@7: jpayne@7: This module contains the set of Requests' exceptions. jpayne@7: """ jpayne@7: from urllib3.exceptions import HTTPError as BaseHTTPError jpayne@7: jpayne@7: from .compat import JSONDecodeError as CompatJSONDecodeError jpayne@7: jpayne@7: jpayne@7: class RequestException(IOError): jpayne@7: """There was an ambiguous exception that occurred while handling your jpayne@7: request. jpayne@7: """ jpayne@7: jpayne@7: def __init__(self, *args, **kwargs): jpayne@7: """Initialize RequestException with `request` and `response` objects.""" jpayne@7: response = kwargs.pop("response", None) jpayne@7: self.response = response jpayne@7: self.request = kwargs.pop("request", None) jpayne@7: if response is not None and not self.request and hasattr(response, "request"): jpayne@7: self.request = self.response.request jpayne@7: super().__init__(*args, **kwargs) jpayne@7: jpayne@7: jpayne@7: class InvalidJSONError(RequestException): jpayne@7: """A JSON error occurred.""" jpayne@7: jpayne@7: jpayne@7: class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError): jpayne@7: """Couldn't decode the text into json""" jpayne@7: jpayne@7: def __init__(self, *args, **kwargs): jpayne@7: """ jpayne@7: Construct the JSONDecodeError instance first with all jpayne@7: args. Then use it's args to construct the IOError so that jpayne@7: the json specific args aren't used as IOError specific args jpayne@7: and the error message from JSONDecodeError is preserved. jpayne@7: """ jpayne@7: CompatJSONDecodeError.__init__(self, *args) jpayne@7: InvalidJSONError.__init__(self, *self.args, **kwargs) jpayne@7: jpayne@7: jpayne@7: class HTTPError(RequestException): jpayne@7: """An HTTP error occurred.""" jpayne@7: jpayne@7: jpayne@7: class ConnectionError(RequestException): jpayne@7: """A Connection error occurred.""" jpayne@7: jpayne@7: jpayne@7: class ProxyError(ConnectionError): jpayne@7: """A proxy error occurred.""" jpayne@7: jpayne@7: jpayne@7: class SSLError(ConnectionError): jpayne@7: """An SSL error occurred.""" jpayne@7: jpayne@7: jpayne@7: class Timeout(RequestException): jpayne@7: """The request timed out. jpayne@7: jpayne@7: Catching this error will catch both jpayne@7: :exc:`~requests.exceptions.ConnectTimeout` and jpayne@7: :exc:`~requests.exceptions.ReadTimeout` errors. jpayne@7: """ jpayne@7: jpayne@7: jpayne@7: class ConnectTimeout(ConnectionError, Timeout): jpayne@7: """The request timed out while trying to connect to the remote server. jpayne@7: jpayne@7: Requests that produced this error are safe to retry. jpayne@7: """ jpayne@7: jpayne@7: jpayne@7: class ReadTimeout(Timeout): jpayne@7: """The server did not send any data in the allotted amount of time.""" jpayne@7: jpayne@7: jpayne@7: class URLRequired(RequestException): jpayne@7: """A valid URL is required to make a request.""" jpayne@7: jpayne@7: jpayne@7: class TooManyRedirects(RequestException): jpayne@7: """Too many redirects.""" jpayne@7: jpayne@7: jpayne@7: class MissingSchema(RequestException, ValueError): jpayne@7: """The URL scheme (e.g. http or https) is missing.""" jpayne@7: jpayne@7: jpayne@7: class InvalidSchema(RequestException, ValueError): jpayne@7: """The URL scheme provided is either invalid or unsupported.""" jpayne@7: jpayne@7: jpayne@7: class InvalidURL(RequestException, ValueError): jpayne@7: """The URL provided was somehow invalid.""" jpayne@7: jpayne@7: jpayne@7: class InvalidHeader(RequestException, ValueError): jpayne@7: """The header value provided was somehow invalid.""" jpayne@7: jpayne@7: jpayne@7: class InvalidProxyURL(InvalidURL): jpayne@7: """The proxy URL provided is invalid.""" jpayne@7: jpayne@7: jpayne@7: class ChunkedEncodingError(RequestException): jpayne@7: """The server declared chunked encoding but sent an invalid chunk.""" jpayne@7: jpayne@7: jpayne@7: class ContentDecodingError(RequestException, BaseHTTPError): jpayne@7: """Failed to decode response content.""" jpayne@7: jpayne@7: jpayne@7: class StreamConsumedError(RequestException, TypeError): jpayne@7: """The content for this response was already consumed.""" jpayne@7: jpayne@7: jpayne@7: class RetryError(RequestException): jpayne@7: """Custom retries logic failed""" jpayne@7: jpayne@7: jpayne@7: class UnrewindableBodyError(RequestException): jpayne@7: """Requests encountered an error when trying to rewind a body.""" jpayne@7: jpayne@7: jpayne@7: # Warnings jpayne@7: jpayne@7: jpayne@7: class RequestsWarning(Warning): jpayne@7: """Base warning for Requests.""" jpayne@7: jpayne@7: jpayne@7: class FileModeWarning(RequestsWarning, DeprecationWarning): jpayne@7: """A file was opened in text mode, but Requests determined its binary length.""" jpayne@7: jpayne@7: jpayne@7: class RequestsDependencyWarning(RequestsWarning): jpayne@7: """An imported dependency doesn't match the expected version range."""