1
0

exceptions.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 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