]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/urllib3/exceptions.py
1 from __future__
import absolute_import
3 from .packages
.six
.moves
.http_client
import IncompleteRead
as httplib_IncompleteRead
8 class HTTPError(Exception):
9 """Base exception used by this module."""
14 class HTTPWarning(Warning):
15 """Base warning used by this module."""
20 class PoolError(HTTPError
):
21 """Base exception for errors caused within a pool."""
23 def __init__(self
, pool
, message
):
25 HTTPError
.__init
__(self
, "%s: %s" % (pool
, message
))
28 # For pickling purposes.
29 return self
.__class
__, (None, None)
32 class RequestError(PoolError
):
33 """Base exception for PoolErrors that have associated URLs."""
35 def __init__(self
, pool
, url
, message
):
37 PoolError
.__init
__(self
, pool
, message
)
40 # For pickling purposes.
41 return self
.__class
__, (None, self
.url
, None)
44 class SSLError(HTTPError
):
45 """Raised when SSL certificate fails in an HTTPS connection."""
50 class ProxyError(HTTPError
):
51 """Raised when the connection to a proxy fails."""
53 def __init__(self
, message
, error
, *args
):
54 super(ProxyError
, self
).__init
__(message
, error
, *args
)
55 self
.original_error
= error
58 class DecodeError(HTTPError
):
59 """Raised when automatic decoding based on Content-Type fails."""
64 class ProtocolError(HTTPError
):
65 """Raised when something unexpected happens mid-request/response."""
70 #: Renamed to ProtocolError but aliased for backwards compatibility.
71 ConnectionError
= ProtocolError
77 class MaxRetryError(RequestError
):
78 """Raised when the maximum number of retries is exceeded.
80 :param pool: The connection pool
81 :type pool: :class:`~urllib3.connectionpool.HTTPConnectionPool`
82 :param string url: The requested Url
83 :param exceptions.Exception reason: The underlying error
87 def __init__(self
, pool
, url
, reason
=None):
90 message
= "Max retries exceeded with url: %s (Caused by %r)" % (url
, reason
)
92 RequestError
.__init
__(self
, pool
, url
, message
)
95 class HostChangedError(RequestError
):
96 """Raised when an existing pool gets a request for a foreign host."""
98 def __init__(self
, pool
, url
, retries
=3):
99 message
= "Tried to open a foreign host with url: %s" % url
100 RequestError
.__init
__(self
, pool
, url
, message
)
101 self
.retries
= retries
104 class TimeoutStateError(HTTPError
):
105 """Raised when passing an invalid state to a timeout"""
110 class TimeoutError(HTTPError
):
111 """Raised when a socket timeout error occurs.
113 Catching this error will catch both :exc:`ReadTimeoutErrors
114 <ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.
120 class ReadTimeoutError(TimeoutError
, RequestError
):
121 """Raised when a socket timeout occurs while receiving data from a server"""
126 # This timeout error does not have a URL attached and needs to inherit from the
128 class ConnectTimeoutError(TimeoutError
):
129 """Raised when a socket timeout occurs while connecting to a server"""
134 class NewConnectionError(ConnectTimeoutError
, PoolError
):
135 """Raised when we fail to establish a new connection. Usually ECONNREFUSED."""
140 class EmptyPoolError(PoolError
):
141 """Raised when a pool runs out of connections and no more are allowed."""
146 class ClosedPoolError(PoolError
):
147 """Raised when a request enters a pool after the pool has been closed."""
152 class LocationValueError(ValueError, HTTPError
):
153 """Raised when there is something wrong with a given URL input."""
158 class LocationParseError(LocationValueError
):
159 """Raised when get_host or similar fails to parse the URL input."""
161 def __init__(self
, location
):
162 message
= "Failed to parse: %s" % location
163 HTTPError
.__init
__(self
, message
)
165 self
.location
= location
168 class URLSchemeUnknown(LocationValueError
):
169 """Raised when a URL input has an unsupported scheme."""
171 def __init__(self
, scheme
):
172 message
= "Not supported URL scheme %s" % scheme
173 super(URLSchemeUnknown
, self
).__init
__(message
)
178 class ResponseError(HTTPError
):
179 """Used as a container for an error reason supplied in a MaxRetryError."""
181 GENERIC_ERROR
= "too many error responses"
182 SPECIFIC_ERROR
= "too many {status_code} error responses"
185 class SecurityWarning(HTTPWarning
):
186 """Warned when performing security reducing actions"""
191 class SubjectAltNameWarning(SecurityWarning
):
192 """Warned when connecting to a host with a certificate missing a SAN."""
197 class InsecureRequestWarning(SecurityWarning
):
198 """Warned when making an unverified HTTPS request."""
203 class SystemTimeWarning(SecurityWarning
):
204 """Warned when system time is suspected to be wrong"""
209 class InsecurePlatformWarning(SecurityWarning
):
210 """Warned when certain TLS/SSL configuration is not available on a platform."""
215 class SNIMissingWarning(HTTPWarning
):
216 """Warned when making a HTTPS request without SNI available."""
221 class DependencyWarning(HTTPWarning
):
223 Warned when an attempt is made to import a module with missing optional
230 class ResponseNotChunked(ProtocolError
, ValueError):
231 """Response needs to be chunked in order to read it as chunks."""
236 class BodyNotHttplibCompatible(HTTPError
):
238 Body should be :class:`http.client.HTTPResponse` like
239 (have an fp attribute which returns raw chunks) for read_chunked().
245 class IncompleteRead(HTTPError
, httplib_IncompleteRead
):
247 Response length doesn't match expected Content-Length
249 Subclass of :class:`http.client.IncompleteRead` to allow int value
250 for ``partial`` to avoid creating large objects on streamed reads.
253 def __init__(self
, partial
, expected
):
254 super(IncompleteRead
, self
).__init
__(partial
, expected
)
257 return "IncompleteRead(%i bytes read, %i more expected)" % (
263 class InvalidChunkLength(HTTPError
, httplib_IncompleteRead
):
264 """Invalid chunk length in a chunked response."""
266 def __init__(self
, response
, length
):
267 super(InvalidChunkLength
, self
).__init
__(
268 response
.tell(), response
.length_remaining
270 self
.response
= response
274 return "InvalidChunkLength(got length %r, %i bytes read)" % (
280 class InvalidHeader(HTTPError
):
281 """The header provided was somehow invalid."""
286 class ProxySchemeUnknown(AssertionError, URLSchemeUnknown
):
287 """ProxyManager does not support the supplied scheme"""
289 # TODO(t-8ch): Stop inheriting from AssertionError in v2.0.
291 def __init__(self
, scheme
):
292 # 'localhost' is here because our URL parser parses
293 # localhost:8080 -> scheme=localhost, remove if we fix this.
294 if scheme
== "localhost":
297 message
= "Proxy URL had no scheme, should start with http:// or https://"
300 "Proxy URL had unsupported scheme %s, should use http:// or https://"
303 super(ProxySchemeUnknown
, self
).__init
__(message
)
306 class ProxySchemeUnsupported(ValueError):
307 """Fetching HTTPS resources through HTTPS proxies is unsupported"""
312 class HeaderParsingError(HTTPError
):
313 """Raised by assert_header_parsing, but we convert it to a log.warning statement."""
315 def __init__(self
, defects
, unparsed_data
):
316 message
= "%s, unparsed data: %r" % (defects
or "Unknown", unparsed_data
)
317 super(HeaderParsingError
, self
).__init
__(message
)
320 class UnrewindableBodyError(HTTPError
):
321 """urllib3 encountered an error when trying to rewind a body"""