annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/requests/exceptions.py @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 """
jpayne@68 2 requests.exceptions
jpayne@68 3 ~~~~~~~~~~~~~~~~~~~
jpayne@68 4
jpayne@68 5 This module contains the set of Requests' exceptions.
jpayne@68 6 """
jpayne@68 7 from urllib3.exceptions import HTTPError as BaseHTTPError
jpayne@68 8
jpayne@68 9 from .compat import JSONDecodeError as CompatJSONDecodeError
jpayne@68 10
jpayne@68 11
jpayne@68 12 class RequestException(IOError):
jpayne@68 13 """There was an ambiguous exception that occurred while handling your
jpayne@68 14 request.
jpayne@68 15 """
jpayne@68 16
jpayne@68 17 def __init__(self, *args, **kwargs):
jpayne@68 18 """Initialize RequestException with `request` and `response` objects."""
jpayne@68 19 response = kwargs.pop("response", None)
jpayne@68 20 self.response = response
jpayne@68 21 self.request = kwargs.pop("request", None)
jpayne@68 22 if response is not None and not self.request and hasattr(response, "request"):
jpayne@68 23 self.request = self.response.request
jpayne@68 24 super().__init__(*args, **kwargs)
jpayne@68 25
jpayne@68 26
jpayne@68 27 class InvalidJSONError(RequestException):
jpayne@68 28 """A JSON error occurred."""
jpayne@68 29
jpayne@68 30
jpayne@68 31 class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
jpayne@68 32 """Couldn't decode the text into json"""
jpayne@68 33
jpayne@68 34 def __init__(self, *args, **kwargs):
jpayne@68 35 """
jpayne@68 36 Construct the JSONDecodeError instance first with all
jpayne@68 37 args. Then use it's args to construct the IOError so that
jpayne@68 38 the json specific args aren't used as IOError specific args
jpayne@68 39 and the error message from JSONDecodeError is preserved.
jpayne@68 40 """
jpayne@68 41 CompatJSONDecodeError.__init__(self, *args)
jpayne@68 42 InvalidJSONError.__init__(self, *self.args, **kwargs)
jpayne@68 43
jpayne@68 44 def __reduce__(self):
jpayne@68 45 """
jpayne@68 46 The __reduce__ method called when pickling the object must
jpayne@68 47 be the one from the JSONDecodeError (be it json/simplejson)
jpayne@68 48 as it expects all the arguments for instantiation, not just
jpayne@68 49 one like the IOError, and the MRO would by default call the
jpayne@68 50 __reduce__ method from the IOError due to the inheritance order.
jpayne@68 51 """
jpayne@68 52 return CompatJSONDecodeError.__reduce__(self)
jpayne@68 53
jpayne@68 54
jpayne@68 55 class HTTPError(RequestException):
jpayne@68 56 """An HTTP error occurred."""
jpayne@68 57
jpayne@68 58
jpayne@68 59 class ConnectionError(RequestException):
jpayne@68 60 """A Connection error occurred."""
jpayne@68 61
jpayne@68 62
jpayne@68 63 class ProxyError(ConnectionError):
jpayne@68 64 """A proxy error occurred."""
jpayne@68 65
jpayne@68 66
jpayne@68 67 class SSLError(ConnectionError):
jpayne@68 68 """An SSL error occurred."""
jpayne@68 69
jpayne@68 70
jpayne@68 71 class Timeout(RequestException):
jpayne@68 72 """The request timed out.
jpayne@68 73
jpayne@68 74 Catching this error will catch both
jpayne@68 75 :exc:`~requests.exceptions.ConnectTimeout` and
jpayne@68 76 :exc:`~requests.exceptions.ReadTimeout` errors.
jpayne@68 77 """
jpayne@68 78
jpayne@68 79
jpayne@68 80 class ConnectTimeout(ConnectionError, Timeout):
jpayne@68 81 """The request timed out while trying to connect to the remote server.
jpayne@68 82
jpayne@68 83 Requests that produced this error are safe to retry.
jpayne@68 84 """
jpayne@68 85
jpayne@68 86
jpayne@68 87 class ReadTimeout(Timeout):
jpayne@68 88 """The server did not send any data in the allotted amount of time."""
jpayne@68 89
jpayne@68 90
jpayne@68 91 class URLRequired(RequestException):
jpayne@68 92 """A valid URL is required to make a request."""
jpayne@68 93
jpayne@68 94
jpayne@68 95 class TooManyRedirects(RequestException):
jpayne@68 96 """Too many redirects."""
jpayne@68 97
jpayne@68 98
jpayne@68 99 class MissingSchema(RequestException, ValueError):
jpayne@68 100 """The URL scheme (e.g. http or https) is missing."""
jpayne@68 101
jpayne@68 102
jpayne@68 103 class InvalidSchema(RequestException, ValueError):
jpayne@68 104 """The URL scheme provided is either invalid or unsupported."""
jpayne@68 105
jpayne@68 106
jpayne@68 107 class InvalidURL(RequestException, ValueError):
jpayne@68 108 """The URL provided was somehow invalid."""
jpayne@68 109
jpayne@68 110
jpayne@68 111 class InvalidHeader(RequestException, ValueError):
jpayne@68 112 """The header value provided was somehow invalid."""
jpayne@68 113
jpayne@68 114
jpayne@68 115 class InvalidProxyURL(InvalidURL):
jpayne@68 116 """The proxy URL provided is invalid."""
jpayne@68 117
jpayne@68 118
jpayne@68 119 class ChunkedEncodingError(RequestException):
jpayne@68 120 """The server declared chunked encoding but sent an invalid chunk."""
jpayne@68 121
jpayne@68 122
jpayne@68 123 class ContentDecodingError(RequestException, BaseHTTPError):
jpayne@68 124 """Failed to decode response content."""
jpayne@68 125
jpayne@68 126
jpayne@68 127 class StreamConsumedError(RequestException, TypeError):
jpayne@68 128 """The content for this response was already consumed."""
jpayne@68 129
jpayne@68 130
jpayne@68 131 class RetryError(RequestException):
jpayne@68 132 """Custom retries logic failed"""
jpayne@68 133
jpayne@68 134
jpayne@68 135 class UnrewindableBodyError(RequestException):
jpayne@68 136 """Requests encountered an error when trying to rewind a body."""
jpayne@68 137
jpayne@68 138
jpayne@68 139 # Warnings
jpayne@68 140
jpayne@68 141
jpayne@68 142 class RequestsWarning(Warning):
jpayne@68 143 """Base warning for Requests."""
jpayne@68 144
jpayne@68 145
jpayne@68 146 class FileModeWarning(RequestsWarning, DeprecationWarning):
jpayne@68 147 """A file was opened in text mode, but Requests determined its binary length."""
jpayne@68 148
jpayne@68 149
jpayne@68 150 class RequestsDependencyWarning(RequestsWarning):
jpayne@68 151 """An imported dependency doesn't match the expected version range."""