exceptions.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # -*- coding: utf-8 -*-
  2. """
  3. requests.exceptions
  4. ~~~~~~~~~~~~~~~~~~~
  5. This module contains the set of Requests' exceptions.
  6. """
  7. from pip._vendor.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 ChunkedEncodingError(RequestException):
  54. """The server declared chunked encoding but sent an invalid chunk."""
  55. class ContentDecodingError(RequestException, BaseHTTPError):
  56. """Failed to decode response content"""
  57. class StreamConsumedError(RequestException, TypeError):
  58. """The content for this response was already consumed"""
  59. class RetryError(RequestException):
  60. """Custom retries logic failed"""
  61. class UnrewindableBodyError(RequestException):
  62. """Requests encountered an error when trying to rewind a body"""
  63. # Warnings
  64. class RequestsWarning(Warning):
  65. """Base warning for Requests."""
  66. pass
  67. class FileModeWarning(RequestsWarning, DeprecationWarning):
  68. """A file was opened in text mode, but Requests determined its binary length."""
  69. pass
  70. class RequestsDependencyWarning(RequestsWarning):
  71. """An imported dependency doesn't match the expected version range."""
  72. pass