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