Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
exceptions.py142 linesDownload Raw Back to requests
1"""2requests.exceptions3~~~~~~~~~~~~~~~~~~~4 5This module contains the set of Requests' exceptions.6"""7from urllib3.exceptions import HTTPError as BaseHTTPError8 9from .compat import JSONDecodeError as CompatJSONDecodeError10 11 12class RequestException(IOError):13    """There was an ambiguous exception that occurred while handling your14    request.15    """16 17    def __init__(self, *args, **kwargs):18        """Initialize RequestException with `request` and `response` objects."""19        response = kwargs.pop("response", None)20        self.response = response21        self.request = kwargs.pop("request", None)22        if response is not None and not self.request and hasattr(response, "request"):23            self.request = self.response.request24        super().__init__(*args, **kwargs)25 26 27class InvalidJSONError(RequestException):28    """A JSON error occurred."""29 30 31class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):32    """Couldn't decode the text into json"""33 34    def __init__(self, *args, **kwargs):35        """36        Construct the JSONDecodeError instance first with all37        args. Then use it's args to construct the IOError so that38        the json specific args aren't used as IOError specific args39        and the error message from JSONDecodeError is preserved.40        """41        CompatJSONDecodeError.__init__(self, *args)42        InvalidJSONError.__init__(self, *self.args, **kwargs)43 44 45class HTTPError(RequestException):46    """An HTTP error occurred."""47 48 49class ConnectionError(RequestException):50    """A Connection error occurred."""51 52 53class ProxyError(ConnectionError):54    """A proxy error occurred."""55 56 57class SSLError(ConnectionError):58    """An SSL error occurred."""59 60 61class Timeout(RequestException):62    """The request timed out.63 64    Catching this error will catch both65    :exc:`~requests.exceptions.ConnectTimeout` and66    :exc:`~requests.exceptions.ReadTimeout` errors.67    """68 69 70class ConnectTimeout(ConnectionError, Timeout):71    """The request timed out while trying to connect to the remote server.72 73    Requests that produced this error are safe to retry.74    """75 76 77class ReadTimeout(Timeout):78    """The server did not send any data in the allotted amount of time."""79 80 81class URLRequired(RequestException):82    """A valid URL is required to make a request."""83 84 85class TooManyRedirects(RequestException):86    """Too many redirects."""87 88 89class MissingSchema(RequestException, ValueError):90    """The URL scheme (e.g. http or https) is missing."""91 92 93class InvalidSchema(RequestException, ValueError):94    """The URL scheme provided is either invalid or unsupported."""95 96 97class InvalidURL(RequestException, ValueError):98    """The URL provided was somehow invalid."""99 100 101class InvalidHeader(RequestException, ValueError):102    """The header value provided was somehow invalid."""103 104 105class InvalidProxyURL(InvalidURL):106    """The proxy URL provided is invalid."""107 108 109class ChunkedEncodingError(RequestException):110    """The server declared chunked encoding but sent an invalid chunk."""111 112 113class ContentDecodingError(RequestException, BaseHTTPError):114    """Failed to decode response content."""115 116 117class StreamConsumedError(RequestException, TypeError):118    """The content for this response was already consumed."""119 120 121class RetryError(RequestException):122    """Custom retries logic failed"""123 124 125class UnrewindableBodyError(RequestException):126    """Requests encountered an error when trying to rewind a body."""127 128 129# Warnings130 131 132class RequestsWarning(Warning):133    """Base warning for Requests."""134 135 136class FileModeWarning(RequestsWarning, DeprecationWarning):137    """A file was opened in text mode, but Requests determined its binary length."""138 139 140class RequestsDependencyWarning(RequestsWarning):141    """An imported dependency doesn't match the expected version range."""142 
codekingpro/portable-devtools · Team Ai