annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/requests/exceptions.py @ 69:33d812a61356

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