exceptions.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # -*- coding: utf-8 -*-
  2. """
  3. requests.exceptions
  4. ~~~~~~~~~~~~~~~~~~~
  5. This module contains the set of Requests' exceptions.
  6. """
  7. from .packages.urllib3.exceptions import HTTPError as BaseHTTPError
  8. class RequestException(IOError):
  9. """There was an ambiguous exception that occurred while handling your
  10. request."""
  11. def __init__(self, *args, **kwargs):
  12. """
  13. Initialize RequestException with `request` and `response` objects.
  14. """
  15. response = kwargs.pop('response', None)
  16. self.response = response
  17. self.request = kwargs.pop('request', None)
  18. if (response is not None and not self.request and
  19. hasattr(response, 'request')):
  20. self.request = self.response.request
  21. super(RequestException, self).__init__(*args, **kwargs)
  22. class HTTPError(RequestException):
  23. """An HTTP error occurred."""
  24. class ConnectionError(RequestException):
  25. """A Connection error occurred."""
  26. class ProxyError(ConnectionError):
  27. """A proxy error occurred."""
  28. class SSLError(ConnectionError):
  29. """An SSL error occurred."""
  30. class Timeout(RequestException):
  31. """The request timed out.
  32. Catching this error will catch both
  33. :exc:`~requests.exceptions.ConnectTimeout` and
  34. :exc:`~requests.exceptions.ReadTimeout` errors.
  35. """
  36. class ConnectTimeout(ConnectionError, Timeout):
  37. """The request timed out while trying to connect to the remote server.
  38. Requests that produced this error are safe to retry.
  39. """
  40. class ReadTimeout(Timeout):
  41. """The server did not send any data in the allotted amount of time."""
  42. class URLRequired(RequestException):
  43. """A valid URL is required to make a request."""
  44. class TooManyRedirects(RequestException):
  45. """Too many redirects."""
  46. class MissingSchema(RequestException, ValueError):
  47. """The URL schema (e.g. http or https) is missing."""
  48. class InvalidSchema(RequestException, ValueError):
  49. """See defaults.py for valid schemas."""
  50. class InvalidURL(RequestException, ValueError):
  51. """ The URL provided was somehow invalid. """
  52. class ChunkedEncodingError(RequestException):
  53. """The server declared chunked encoding but sent an invalid chunk."""
  54. class ContentDecodingError(RequestException, BaseHTTPError):
  55. """Failed to decode response content"""
  56. class StreamConsumedError(RequestException, TypeError):
  57. """The content for this response was already consumed"""
  58. class RetryError(RequestException):
  59. """Custom retries logic failed"""