Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/requests/exceptions.py: 90%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2requests.exceptions
3~~~~~~~~~~~~~~~~~~~
5This module contains the set of Requests' exceptions.
6"""
8from urllib3.exceptions import HTTPError as BaseHTTPError
10from .compat import JSONDecodeError as CompatJSONDecodeError
13class RequestException(IOError):
14 """There was an ambiguous exception that occurred while handling your
15 request.
16 """
18 def __init__(self, *args, **kwargs):
19 """Initialize RequestException with `request` and `response` objects."""
20 response = kwargs.pop("response", None)
21 self.response = response
22 self.request = kwargs.pop("request", None)
23 if response is not None and not self.request and hasattr(response, "request"):
24 self.request = self.response.request
25 super().__init__(*args, **kwargs)
28class InvalidJSONError(RequestException):
29 """A JSON error occurred."""
32class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
33 """Couldn't decode the text into json"""
35 def __init__(self, *args, **kwargs):
36 """
37 Construct the JSONDecodeError instance first with all
38 args. Then use it's args to construct the IOError so that
39 the json specific args aren't used as IOError specific args
40 and the error message from JSONDecodeError is preserved.
41 """
42 CompatJSONDecodeError.__init__(self, *args)
43 InvalidJSONError.__init__(self, *self.args, **kwargs)
45 def __reduce__(self):
46 """
47 The __reduce__ method called when pickling the object must
48 be the one from the JSONDecodeError (be it json/simplejson)
49 as it expects all the arguments for instantiation, not just
50 one like the IOError, and the MRO would by default call the
51 __reduce__ method from the IOError due to the inheritance order.
52 """
53 return CompatJSONDecodeError.__reduce__(self)
56class HTTPError(RequestException):
57 """An HTTP error occurred."""
60class ConnectionError(RequestException):
61 """A Connection error occurred."""
64class ProxyError(ConnectionError):
65 """A proxy error occurred."""
68class SSLError(ConnectionError):
69 """An SSL error occurred."""
72class Timeout(RequestException):
73 """The request timed out.
75 Catching this error will catch both
76 :exc:`~requests.exceptions.ConnectTimeout` and
77 :exc:`~requests.exceptions.ReadTimeout` errors.
78 """
81class ConnectTimeout(ConnectionError, Timeout):
82 """The request timed out while trying to connect to the remote server.
84 Requests that produced this error are safe to retry.
85 """
88class ReadTimeout(Timeout):
89 """The server did not send any data in the allotted amount of time."""
92class URLRequired(RequestException):
93 """A valid URL is required to make a request."""
96class TooManyRedirects(RequestException):
97 """Too many redirects."""
100class MissingSchema(RequestException, ValueError):
101 """The URL scheme (e.g. http or https) is missing."""
104class InvalidSchema(RequestException, ValueError):
105 """The URL scheme provided is either invalid or unsupported."""
108class InvalidURL(RequestException, ValueError):
109 """The URL provided was somehow invalid."""
112class InvalidHeader(RequestException, ValueError):
113 """The header value provided was somehow invalid."""
116class InvalidProxyURL(InvalidURL):
117 """The proxy URL provided is invalid."""
120class ChunkedEncodingError(RequestException):
121 """The server declared chunked encoding but sent an invalid chunk."""
124class ContentDecodingError(RequestException, BaseHTTPError):
125 """Failed to decode response content."""
128class StreamConsumedError(RequestException, TypeError):
129 """The content for this response was already consumed."""
132class RetryError(RequestException):
133 """Custom retries logic failed"""
136class UnrewindableBodyError(RequestException):
137 """Requests encountered an error when trying to rewind a body."""
140# Warnings
143class RequestsWarning(Warning):
144 """Base warning for Requests."""
147class FileModeWarning(RequestsWarning, DeprecationWarning):
148 """A file was opened in text mode, but Requests determined its binary length."""
151class RequestsDependencyWarning(RequestsWarning):
152 """An imported dependency doesn't match the expected version range."""