annotate requests/exceptions.py @ 16:dc2c003078e9 tip

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