Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/requests/exceptions.py: 78%
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 __future__ import annotations
10from typing import TYPE_CHECKING, Any
12from urllib3.exceptions import HTTPError as BaseHTTPError
14from .compat import JSONDecodeError as CompatJSONDecodeError
16if TYPE_CHECKING:
17 from .models import PreparedRequest, Request, Response
20class RequestException(IOError):
21 """There was an ambiguous exception that occurred while handling your
22 request.
23 """
25 response: Response | None
26 request: Request | PreparedRequest | None
28 def __init__(self, *args: Any, **kwargs: Any) -> None:
29 """Initialize RequestException with `request` and `response` objects."""
30 response: Response | None = kwargs.pop("response", None)
31 self.response = response
32 self.request = kwargs.pop("request", None)
33 if response is not None and not self.request and hasattr(response, "request"):
34 self.request = response.request
35 super().__init__(*args, **kwargs)
38class InvalidJSONError(RequestException):
39 """A JSON error occurred."""
42class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
43 """Couldn't decode the text into json"""
45 def __init__(self, *args: Any, **kwargs: Any) -> None:
46 """
47 Construct the JSONDecodeError instance first with all
48 args. Then use it's args to construct the IOError so that
49 the json specific args aren't used as IOError specific args
50 and the error message from JSONDecodeError is preserved.
51 """
52 CompatJSONDecodeError.__init__(self, *args)
53 InvalidJSONError.__init__(self, *self.args, **kwargs)
55 def __reduce__(self) -> tuple[Any, ...] | str:
56 """
57 The __reduce__ method called when pickling the object must
58 be the one from the JSONDecodeError (be it json/simplejson)
59 as it expects all the arguments for instantiation, not just
60 one like the IOError, and the MRO would by default call the
61 __reduce__ method from the IOError due to the inheritance order.
62 """
63 return CompatJSONDecodeError.__reduce__(self)
66class HTTPError(RequestException):
67 """An HTTP error occurred."""
70class ConnectionError(RequestException):
71 """A Connection error occurred."""
74class ProxyError(ConnectionError):
75 """A proxy error occurred."""
78class SSLError(ConnectionError):
79 """An SSL error occurred."""
82class Timeout(RequestException):
83 """The request timed out.
85 Catching this error will catch both
86 :exc:`~requests.exceptions.ConnectTimeout` and
87 :exc:`~requests.exceptions.ReadTimeout` errors.
88 """
91class ConnectTimeout(ConnectionError, Timeout):
92 """The request timed out while trying to connect to the remote server.
94 Requests that produced this error are safe to retry.
95 """
98class ReadTimeout(Timeout):
99 """The server did not send any data in the allotted amount of time."""
102class URLRequired(RequestException):
103 """A valid URL is required to make a request."""
106class TooManyRedirects(RequestException):
107 """Too many redirects."""
110class MissingSchema(RequestException, ValueError):
111 """The URL scheme (e.g. http or https) is missing."""
114class InvalidSchema(RequestException, ValueError):
115 """The URL scheme provided is either invalid or unsupported."""
118class InvalidURL(RequestException, ValueError):
119 """The URL provided was somehow invalid."""
122class InvalidHeader(RequestException, ValueError):
123 """The header value provided was somehow invalid."""
126class InvalidProxyURL(InvalidURL):
127 """The proxy URL provided is invalid."""
130class ChunkedEncodingError(RequestException):
131 """The server declared chunked encoding but sent an invalid chunk."""
134class ContentDecodingError(RequestException, BaseHTTPError):
135 """Failed to decode response content."""
138class StreamConsumedError(RequestException, TypeError):
139 """The content for this response was already consumed."""
142class RetryError(RequestException):
143 """Custom retries logic failed"""
146class UnrewindableBodyError(RequestException):
147 """Requests encountered an error when trying to rewind a body."""
150# Warnings
153class RequestsWarning(Warning):
154 """Base warning for Requests."""
157class FileModeWarning(RequestsWarning, DeprecationWarning):
158 """A file was opened in text mode, but Requests determined its binary length."""
161class RequestsDependencyWarning(RequestsWarning):
162 """An imported dependency doesn't match the expected version range."""