You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.1 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. requests.exceptions
  4. ~~~~~~~~~~~~~~~~~~~
  5. This module contains the set of Requests' exceptions.
  6. """
  7. from urllib3.exceptions import HTTPError as BaseHTTPError
  8. class RequestException(IOError):
  9. """There was an ambiguous exception that occurred while handling your
  10. request.
  11. """
  12. def __init__(self, *args, **kwargs):
  13. """Initialize RequestException with `request` and `response` objects."""
  14. response = kwargs.pop('response', None)
  15. self.response = response
  16. self.request = kwargs.pop('request', None)
  17. if (response is not None and not self.request and
  18. hasattr(response, 'request')):
  19. self.request = self.response.request
  20. super(RequestException, self).__init__(*args, **kwargs)
  21. class HTTPError(RequestException):
  22. """An HTTP error occurred."""
  23. class ConnectionError(RequestException):
  24. """A Connection error occurred."""
  25. class ProxyError(ConnectionError):
  26. """A proxy error occurred."""
  27. class SSLError(ConnectionError):
  28. """An SSL error occurred."""
  29. class Timeout(RequestException):
  30. """The request timed out.
  31. Catching this error will catch both
  32. :exc:`~requests.exceptions.ConnectTimeout` and
  33. :exc:`~requests.exceptions.ReadTimeout` errors.
  34. """
  35. class ConnectTimeout(ConnectionError, Timeout):
  36. """The request timed out while trying to connect to the remote server.
  37. Requests that produced this error are safe to retry.
  38. """
  39. class ReadTimeout(Timeout):
  40. """The server did not send any data in the allotted amount of time."""
  41. class URLRequired(RequestException):
  42. """A valid URL is required to make a request."""
  43. class TooManyRedirects(RequestException):
  44. """Too many redirects."""
  45. class MissingSchema(RequestException, ValueError):
  46. """The URL schema (e.g. http or https) is missing."""
  47. class InvalidSchema(RequestException, ValueError):
  48. """See defaults.py for valid schemas."""
  49. class InvalidURL(RequestException, ValueError):
  50. """The URL provided was somehow invalid."""
  51. class InvalidHeader(RequestException, ValueError):
  52. """The header value provided was somehow invalid."""
  53. class InvalidProxyURL(InvalidURL):
  54. """The proxy URL provided is invalid."""
  55. class ChunkedEncodingError(RequestException):
  56. """The server declared chunked encoding but sent an invalid chunk."""
  57. class ContentDecodingError(RequestException, BaseHTTPError):
  58. """Failed to decode response content"""
  59. class StreamConsumedError(RequestException, TypeError):
  60. """The content for this response was already consumed"""
  61. class RetryError(RequestException):
  62. """Custom retries logic failed"""
  63. class UnrewindableBodyError(RequestException):
  64. """Requests encountered an error when trying to rewind a body"""
  65. # Warnings
  66. class RequestsWarning(Warning):
  67. """Base warning for Requests."""
  68. pass
  69. class FileModeWarning(RequestsWarning, DeprecationWarning):
  70. """A file was opened in text mode, but Requests determined its binary length."""
  71. pass
  72. class RequestsDependencyWarning(RequestsWarning):
  73. """An imported dependency doesn't match the expected version range."""
  74. pass