|
|
@ -5,17 +5,19 @@ from .packages.six.moves.http_client import IncompleteRead as httplib_Incomplete |
|
|
|
|
|
|
|
|
|
|
|
class HTTPError(Exception): |
|
|
|
"Base exception used by this module." |
|
|
|
"""Base exception used by this module.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class HTTPWarning(Warning): |
|
|
|
"Base warning used by this module." |
|
|
|
"""Base warning used by this module.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class PoolError(HTTPError): |
|
|
|
"Base exception for errors caused within a pool." |
|
|
|
"""Base exception for errors caused within a pool.""" |
|
|
|
|
|
|
|
def __init__(self, pool, message): |
|
|
|
self.pool = pool |
|
|
@ -27,7 +29,7 @@ class PoolError(HTTPError): |
|
|
|
|
|
|
|
|
|
|
|
class RequestError(PoolError): |
|
|
|
"Base exception for PoolErrors that have associated URLs." |
|
|
|
"""Base exception for PoolErrors that have associated URLs.""" |
|
|
|
|
|
|
|
def __init__(self, pool, url, message): |
|
|
|
self.url = url |
|
|
@ -39,12 +41,13 @@ class RequestError(PoolError): |
|
|
|
|
|
|
|
|
|
|
|
class SSLError(HTTPError): |
|
|
|
"Raised when SSL certificate fails in an HTTPS connection." |
|
|
|
"""Raised when SSL certificate fails in an HTTPS connection.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class ProxyError(HTTPError): |
|
|
|
"Raised when the connection to a proxy fails." |
|
|
|
"""Raised when the connection to a proxy fails.""" |
|
|
|
|
|
|
|
def __init__(self, message, error, *args): |
|
|
|
super(ProxyError, self).__init__(message, error, *args) |
|
|
@ -52,12 +55,14 @@ class ProxyError(HTTPError): |
|
|
|
|
|
|
|
|
|
|
|
class DecodeError(HTTPError): |
|
|
|
"Raised when automatic decoding based on Content-Type fails." |
|
|
|
"""Raised when automatic decoding based on Content-Type fails.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class ProtocolError(HTTPError): |
|
|
|
"Raised when something unexpected happens mid-request/response." |
|
|
|
"""Raised when something unexpected happens mid-request/response.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
@ -87,7 +92,7 @@ class MaxRetryError(RequestError): |
|
|
|
|
|
|
|
|
|
|
|
class HostChangedError(RequestError): |
|
|
|
"Raised when an existing pool gets a request for a foreign host." |
|
|
|
"""Raised when an existing pool gets a request for a foreign host.""" |
|
|
|
|
|
|
|
def __init__(self, pool, url, retries=3): |
|
|
|
message = "Tried to open a foreign host with url: %s" % url |
|
|
@ -96,13 +101,13 @@ class HostChangedError(RequestError): |
|
|
|
|
|
|
|
|
|
|
|
class TimeoutStateError(HTTPError): |
|
|
|
""" Raised when passing an invalid state to a timeout """ |
|
|
|
"""Raised when passing an invalid state to a timeout""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class TimeoutError(HTTPError): |
|
|
|
""" Raised when a socket timeout error occurs. |
|
|
|
"""Raised when a socket timeout error occurs. |
|
|
|
|
|
|
|
Catching this error will catch both :exc:`ReadTimeoutErrors |
|
|
|
<ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`. |
|
|
@ -112,39 +117,45 @@ class TimeoutError(HTTPError): |
|
|
|
|
|
|
|
|
|
|
|
class ReadTimeoutError(TimeoutError, RequestError): |
|
|
|
"Raised when a socket timeout occurs while receiving data from a server" |
|
|
|
"""Raised when a socket timeout occurs while receiving data from a server""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
# This timeout error does not have a URL attached and needs to inherit from the |
|
|
|
# base HTTPError |
|
|
|
class ConnectTimeoutError(TimeoutError): |
|
|
|
"Raised when a socket timeout occurs while connecting to a server" |
|
|
|
"""Raised when a socket timeout occurs while connecting to a server""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class NewConnectionError(ConnectTimeoutError, PoolError): |
|
|
|
"Raised when we fail to establish a new connection. Usually ECONNREFUSED." |
|
|
|
"""Raised when we fail to establish a new connection. Usually ECONNREFUSED.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class EmptyPoolError(PoolError): |
|
|
|
"Raised when a pool runs out of connections and no more are allowed." |
|
|
|
"""Raised when a pool runs out of connections and no more are allowed.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class ClosedPoolError(PoolError): |
|
|
|
"Raised when a request enters a pool after the pool has been closed." |
|
|
|
"""Raised when a request enters a pool after the pool has been closed.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class LocationValueError(ValueError, HTTPError): |
|
|
|
"Raised when there is something wrong with a given URL input." |
|
|
|
"""Raised when there is something wrong with a given URL input.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class LocationParseError(LocationValueError): |
|
|
|
"Raised when get_host or similar fails to parse the URL input." |
|
|
|
"""Raised when get_host or similar fails to parse the URL input.""" |
|
|
|
|
|
|
|
def __init__(self, location): |
|
|
|
message = "Failed to parse: %s" % location |
|
|
@ -154,7 +165,7 @@ class LocationParseError(LocationValueError): |
|
|
|
|
|
|
|
|
|
|
|
class URLSchemeUnknown(LocationValueError): |
|
|
|
"Raised when a URL input has an unsupported scheme." |
|
|
|
"""Raised when a URL input has an unsupported scheme.""" |
|
|
|
|
|
|
|
def __init__(self, scheme): |
|
|
|
message = "Not supported URL scheme %s" % scheme |
|
|
@ -164,38 +175,45 @@ class URLSchemeUnknown(LocationValueError): |
|
|
|
|
|
|
|
|
|
|
|
class ResponseError(HTTPError): |
|
|
|
"Used as a container for an error reason supplied in a MaxRetryError." |
|
|
|
"""Used as a container for an error reason supplied in a MaxRetryError.""" |
|
|
|
|
|
|
|
GENERIC_ERROR = "too many error responses" |
|
|
|
SPECIFIC_ERROR = "too many {status_code} error responses" |
|
|
|
|
|
|
|
|
|
|
|
class SecurityWarning(HTTPWarning): |
|
|
|
"Warned when performing security reducing actions" |
|
|
|
"""Warned when performing security reducing actions""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class SubjectAltNameWarning(SecurityWarning): |
|
|
|
"Warned when connecting to a host with a certificate missing a SAN." |
|
|
|
"""Warned when connecting to a host with a certificate missing a SAN.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class InsecureRequestWarning(SecurityWarning): |
|
|
|
"Warned when making an unverified HTTPS request." |
|
|
|
"""Warned when making an unverified HTTPS request.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class SystemTimeWarning(SecurityWarning): |
|
|
|
"Warned when system time is suspected to be wrong" |
|
|
|
"""Warned when system time is suspected to be wrong""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class InsecurePlatformWarning(SecurityWarning): |
|
|
|
"Warned when certain SSL configuration is not available on a platform." |
|
|
|
"""Warned when certain TLS/SSL configuration is not available on a platform.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class SNIMissingWarning(HTTPWarning): |
|
|
|
"Warned when making a HTTPS request without SNI available." |
|
|
|
"""Warned when making a HTTPS request without SNI available.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
@ -209,14 +227,15 @@ class DependencyWarning(HTTPWarning): |
|
|
|
|
|
|
|
|
|
|
|
class ResponseNotChunked(ProtocolError, ValueError): |
|
|
|
"Response needs to be chunked in order to read it as chunks." |
|
|
|
"""Response needs to be chunked in order to read it as chunks.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class BodyNotHttplibCompatible(HTTPError): |
|
|
|
""" |
|
|
|
Body should be httplib.HTTPResponse like (have an fp attribute which |
|
|
|
returns raw chunks) for read_chunked(). |
|
|
|
Body should be :class:`http.client.HTTPResponse` like |
|
|
|
(have an fp attribute which returns raw chunks) for read_chunked(). |
|
|
|
""" |
|
|
|
|
|
|
|
pass |
|
|
@ -226,9 +245,8 @@ class IncompleteRead(HTTPError, httplib_IncompleteRead): |
|
|
|
""" |
|
|
|
Response length doesn't match expected Content-Length |
|
|
|
|
|
|
|
Subclass of http_client.IncompleteRead to allow int value |
|
|
|
for `partial` to avoid creating large objects on streamed |
|
|
|
reads. |
|
|
|
Subclass of :class:`http.client.IncompleteRead` to allow int value |
|
|
|
for ``partial`` to avoid creating large objects on streamed reads. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, partial, expected): |
|
|
@ -259,12 +277,14 @@ class InvalidChunkLength(HTTPError, httplib_IncompleteRead): |
|
|
|
|
|
|
|
|
|
|
|
class InvalidHeader(HTTPError): |
|
|
|
"The header provided was somehow invalid." |
|
|
|
"""The header provided was somehow invalid.""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class ProxySchemeUnknown(AssertionError, URLSchemeUnknown): |
|
|
|
"ProxyManager does not support the supplied scheme" |
|
|
|
"""ProxyManager does not support the supplied scheme""" |
|
|
|
|
|
|
|
# TODO(t-8ch): Stop inheriting from AssertionError in v2.0. |
|
|
|
|
|
|
|
def __init__(self, scheme): |
|
|
@ -273,12 +293,13 @@ class ProxySchemeUnknown(AssertionError, URLSchemeUnknown): |
|
|
|
|
|
|
|
|
|
|
|
class ProxySchemeUnsupported(ValueError): |
|
|
|
"Fetching HTTPS resources through HTTPS proxies is unsupported" |
|
|
|
"""Fetching HTTPS resources through HTTPS proxies is unsupported""" |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
class HeaderParsingError(HTTPError): |
|
|
|
"Raised by assert_header_parsing, but we convert it to a log.warning statement." |
|
|
|
"""Raised by assert_header_parsing, but we convert it to a log.warning statement.""" |
|
|
|
|
|
|
|
def __init__(self, defects, unparsed_data): |
|
|
|
message = "%s, unparsed data: %r" % (defects or "Unknown", unparsed_data) |
|
|
@ -286,5 +307,6 @@ class HeaderParsingError(HTTPError): |
|
|
|
|
|
|
|
|
|
|
|
class UnrewindableBodyError(HTTPError): |
|
|
|
"urllib3 encountered an error when trying to rewind a body" |
|
|
|
"""urllib3 encountered an error when trying to rewind a body""" |
|
|
|
|
|
|
|
pass |
|
|
|