Path: blob/master/venv/Lib/site-packages/urllib3/exceptions.py
811 views
from __future__ import absolute_import1from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead23# Base Exceptions456class HTTPError(Exception):7"Base exception used by this module."8pass91011class HTTPWarning(Warning):12"Base warning used by this module."13pass141516class PoolError(HTTPError):17"Base exception for errors caused within a pool."1819def __init__(self, pool, message):20self.pool = pool21HTTPError.__init__(self, "%s: %s" % (pool, message))2223def __reduce__(self):24# For pickling purposes.25return self.__class__, (None, None)262728class RequestError(PoolError):29"Base exception for PoolErrors that have associated URLs."3031def __init__(self, pool, url, message):32self.url = url33PoolError.__init__(self, pool, message)3435def __reduce__(self):36# For pickling purposes.37return self.__class__, (None, self.url, None)383940class SSLError(HTTPError):41"Raised when SSL certificate fails in an HTTPS connection."42pass434445class ProxyError(HTTPError):46"Raised when the connection to a proxy fails."4748def __init__(self, message, error, *args):49super(ProxyError, self).__init__(message, error, *args)50self.original_error = error515253class DecodeError(HTTPError):54"Raised when automatic decoding based on Content-Type fails."55pass565758class ProtocolError(HTTPError):59"Raised when something unexpected happens mid-request/response."60pass616263#: Renamed to ProtocolError but aliased for backwards compatibility.64ConnectionError = ProtocolError656667# Leaf Exceptions686970class MaxRetryError(RequestError):71"""Raised when the maximum number of retries is exceeded.7273:param pool: The connection pool74:type pool: :class:`~urllib3.connectionpool.HTTPConnectionPool`75:param string url: The requested Url76:param exceptions.Exception reason: The underlying error7778"""7980def __init__(self, pool, url, reason=None):81self.reason = reason8283message = "Max retries exceeded with url: %s (Caused by %r)" % (url, reason)8485RequestError.__init__(self, pool, url, message)868788class HostChangedError(RequestError):89"Raised when an existing pool gets a request for a foreign host."9091def __init__(self, pool, url, retries=3):92message = "Tried to open a foreign host with url: %s" % url93RequestError.__init__(self, pool, url, message)94self.retries = retries959697class TimeoutStateError(HTTPError):98""" Raised when passing an invalid state to a timeout """99100pass101102103class TimeoutError(HTTPError):104""" Raised when a socket timeout error occurs.105106Catching this error will catch both :exc:`ReadTimeoutErrors107<ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.108"""109110pass111112113class ReadTimeoutError(TimeoutError, RequestError):114"Raised when a socket timeout occurs while receiving data from a server"115pass116117118# This timeout error does not have a URL attached and needs to inherit from the119# base HTTPError120class ConnectTimeoutError(TimeoutError):121"Raised when a socket timeout occurs while connecting to a server"122pass123124125class NewConnectionError(ConnectTimeoutError, PoolError):126"Raised when we fail to establish a new connection. Usually ECONNREFUSED."127pass128129130class EmptyPoolError(PoolError):131"Raised when a pool runs out of connections and no more are allowed."132pass133134135class ClosedPoolError(PoolError):136"Raised when a request enters a pool after the pool has been closed."137pass138139140class LocationValueError(ValueError, HTTPError):141"Raised when there is something wrong with a given URL input."142pass143144145class LocationParseError(LocationValueError):146"Raised when get_host or similar fails to parse the URL input."147148def __init__(self, location):149message = "Failed to parse: %s" % location150HTTPError.__init__(self, message)151152self.location = location153154155class ResponseError(HTTPError):156"Used as a container for an error reason supplied in a MaxRetryError."157GENERIC_ERROR = "too many error responses"158SPECIFIC_ERROR = "too many {status_code} error responses"159160161class SecurityWarning(HTTPWarning):162"Warned when performing security reducing actions"163pass164165166class SubjectAltNameWarning(SecurityWarning):167"Warned when connecting to a host with a certificate missing a SAN."168pass169170171class InsecureRequestWarning(SecurityWarning):172"Warned when making an unverified HTTPS request."173pass174175176class SystemTimeWarning(SecurityWarning):177"Warned when system time is suspected to be wrong"178pass179180181class InsecurePlatformWarning(SecurityWarning):182"Warned when certain SSL configuration is not available on a platform."183pass184185186class SNIMissingWarning(HTTPWarning):187"Warned when making a HTTPS request without SNI available."188pass189190191class DependencyWarning(HTTPWarning):192"""193Warned when an attempt is made to import a module with missing optional194dependencies.195"""196197pass198199200class InvalidProxyConfigurationWarning(HTTPWarning):201"""202Warned when using an HTTPS proxy and an HTTPS URL. Currently203urllib3 doesn't support HTTPS proxies and the proxy will be204contacted via HTTP instead. This warning can be fixed by205changing your HTTPS proxy URL into an HTTP proxy URL.206207If you encounter this warning read this:208https://github.com/urllib3/urllib3/issues/1850209"""210211pass212213214class ResponseNotChunked(ProtocolError, ValueError):215"Response needs to be chunked in order to read it as chunks."216pass217218219class BodyNotHttplibCompatible(HTTPError):220"""221Body should be httplib.HTTPResponse like (have an fp attribute which222returns raw chunks) for read_chunked().223"""224225pass226227228class IncompleteRead(HTTPError, httplib_IncompleteRead):229"""230Response length doesn't match expected Content-Length231232Subclass of http_client.IncompleteRead to allow int value233for `partial` to avoid creating large objects on streamed234reads.235"""236237def __init__(self, partial, expected):238super(IncompleteRead, self).__init__(partial, expected)239240def __repr__(self):241return "IncompleteRead(%i bytes read, %i more expected)" % (242self.partial,243self.expected,244)245246247class InvalidHeader(HTTPError):248"The header provided was somehow invalid."249pass250251252class ProxySchemeUnknown(AssertionError, ValueError):253"ProxyManager does not support the supplied scheme"254# TODO(t-8ch): Stop inheriting from AssertionError in v2.0.255256def __init__(self, scheme):257message = "Not supported proxy scheme %s" % scheme258super(ProxySchemeUnknown, self).__init__(message)259260261class HeaderParsingError(HTTPError):262"Raised by assert_header_parsing, but we convert it to a log.warning statement."263264def __init__(self, defects, unparsed_data):265message = "%s, unparsed data: %r" % (defects or "Unknown", unparsed_data)266super(HeaderParsingError, self).__init__(message)267268269class UnrewindableBodyError(HTTPError):270"urllib3 encountered an error when trying to rewind a body"271pass272273274