_exceptions.py
This file
Path
httpx/_exceptions.py
168 lines · 2.9 KiB · Python
Last changed by
Drop RedirectLoop exception (#819)Piotr Staroszczykbefore adoptionefe9f61
History of this fileTake it
1import typing23if typing.TYPE_CHECKING:4 from ._models import Request, Response # pragma: nocover567class HTTPError(Exception):8 """9 Base class for all httpx exceptions.10 """1112 def __init__(13 self, *args: typing.Any, request: "Request" = None, response: "Response" = None14 ) -> None:15 self.response = response16 self.request = request or getattr(self.response, "request", None)17 super().__init__(*args)181920# Timeout exceptions...212223class TimeoutException(HTTPError):24 """25 A base class for all timeouts.26 """272829class ConnectTimeout(TimeoutException):30 """31 Timeout while establishing a connection.32 """333435class ReadTimeout(TimeoutException):36 """37 Timeout while reading response data.38 """394041class WriteTimeout(TimeoutException):42 """43 Timeout while writing request data.44 """454647class PoolTimeout(TimeoutException):48 """49 Timeout while waiting to acquire a connection from the pool.50 """515253class ProxyError(HTTPError):54 """55 Error from within a proxy56 """575859# HTTP exceptions...606162class ProtocolError(HTTPError):63 """64 Malformed HTTP.65 """666768class DecodingError(HTTPError):69 """70 Decoding of the response failed.71 """727374# Network exceptions...757677class NetworkError(HTTPError):78 """79 A failure occurred while trying to access the network.80 """818283class ConnectionClosed(NetworkError):84 """85 Expected more data from peer, but connection was closed.86 """878889# Redirect exceptions...909192class RedirectError(HTTPError):93 """94 Base class for HTTP redirect errors.95 """969798class TooManyRedirects(RedirectError):99 """100 Too many redirects.101 """102103104class NotRedirectResponse(RedirectError):105 """106 Response was not a redirect response.107 """108109110# Stream exceptions...111112113class StreamError(HTTPError):114 """115 The base class for stream exceptions.116117 The developer made an error in accessing the request stream in118 an invalid way.119 """120121122class RequestBodyUnavailable(StreamError):123 """124 Had to send the request again, but the request body was streaming, and is125 no longer available.126 """127128129class StreamConsumed(StreamError):130 """131 Attempted to read or stream response content, but the content has already132 been streamed.133 """134135136class ResponseNotRead(StreamError):137 """138 Attempted to access response content, without having called `read()`139 after a streaming response.140 """141142143class RequestNotRead(StreamError):144 """145 Attempted to access request content, without having called `read()`.146 """147148149class ResponseClosed(StreamError):150 """151 Attempted to read or stream response content, but the request has been152 closed.153 """154155156# Other cases...157158159class InvalidURL(HTTPError):160 """161 URL was missing a hostname, or was not one of HTTP/HTTPS.162 """163164165class CookieConflict(HTTPError):166 """167 Attempted to lookup a cookie by name, but multiple cookies existed.168 """