exceptions.py
This file
Path
httpx/exceptions.py
159 lines · 2.7 KiB · Python
Last changed by
Tweak docstringTom Christiebefore adoptiona738327
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# Redirect exceptions...757677class RedirectError(HTTPError):78 """79 Base class for HTTP redirect errors.80 """818283class TooManyRedirects(RedirectError):84 """85 Too many redirects.86 """878889class RedirectBodyUnavailable(RedirectError):90 """91 Got a redirect response, but the request body was streaming, and is92 no longer available.93 """949596class RedirectLoop(RedirectError):97 """98 Infinite redirect loop.99 """100101102class NotRedirectResponse(RedirectError):103 """104 Response was not a redirect response.105 """106107108# Stream exceptions...109110111class StreamError(HTTPError):112 """113 The base class for stream exceptions.114115 The developer made an error in accessing the request stream in116 an invalid way.117 """118119120class StreamConsumed(StreamError):121 """122 Attempted to read or stream response content, but the content has already123 been streamed.124 """125126127class ResponseNotRead(StreamError):128 """129 Attempted to access response content, without having called `read()`130 after a streaming response.131 """132133134class ResponseClosed(StreamError):135 """136 Attempted to read or stream response content, but the request has been137 closed.138 """139140141# Other cases...142143144class InvalidURL(HTTPError):145 """146 URL was missing a hostname, or was not one of HTTP/HTTPS.147 """148149150class ConnectionClosed(HTTPError):151 """152 Expected more data from peer, but connection was closed.153 """154155156class CookieConflict(HTTPError):157 """158 Attempted to lookup a cookie by name, but multiple cookies existed.159 """