Exceptions
This page lists exceptions that may be raised when using HTTPX.
For an overview of how to work with HTTPX exceptions, see Exceptions (Quickstart).
- HTTPError
- RequestError
- TransportError
- TimeoutException
- ConnectTimeout
- ReadTimeout
- WriteTimeout
- PoolTimeout
- NetworkError
- ConnectError
- ReadError
- WriteError
- CloseError
- ProtocolError
- LocalProtocolError
- RemoteProtocolError
- ProxyError
- UnsupportedProtocol
- SSEError
- TimeoutException
- DecodingError
- TooManyRedirects
- TransportError
- HTTPStatusError
- RequestError
- InvalidURL
- CookieConflict
- StreamError
- StreamConsumed
- ResponseNotRead
- RequestNotRead
- StreamClosed
Bases: Exception
Base class for RequestError and HTTPStatusError.
Useful for try...except blocks when issuing a request,
and then calling .raise_for_status().
For example:
try:
response = httpx2.get("https://www.example.com")
response.raise_for_status()
except httpx2.HTTPError as exc:
print(f"HTTP Exception for {exc.request.url} - {exc}")
Bases: HTTPError
Base class for all exceptions that may occur when issuing a .request().
Bases: RequestError
Base class for all exceptions that occur at the level of the Transport API.
Bases: TransportError
The base class for timeout errors.
An operation has timed out.
Bases: TimeoutException
Timed out while connecting to the host.
Bases: TimeoutException
Timed out while receiving data from the host.
Bases: TimeoutException
Timed out while sending data to the host.
Bases: TimeoutException
Timed out waiting to acquire a connection from the pool.
Bases: TransportError
The base class for network-related errors.
An error occurred while interacting with the network.
Bases: NetworkError
Failed to establish a connection.
Bases: NetworkError
Failed to receive data from the network.
Bases: NetworkError
Failed to send data through the network.
Bases: NetworkError
Failed to close a connection.
Bases: TransportError
The protocol was violated.
Bases: ProtocolError
A protocol was violated by the client.
For example if the user instantiated a Request instance explicitly,
failed to include the mandatory Host: header, and then issued it directly
using client.send().
Bases: ProtocolError
The protocol was violated by the server.
For example, returning malformed HTTP.
Bases: TransportError
An error occurred while establishing a proxy connection.
Bases: TransportError
Attempted to make a request to an unsupported protocol.
For example issuing a request to ftp://www.example.com.
Bases: TransportError
An error that occurred while connecting to a server-sent events endpoint.
Bases: RequestError
Decoding of the response failed, due to a malformed encoding.
Bases: RequestError
Too many redirects.
Bases: HTTPError
The response had an error HTTP status of 4xx or 5xx.
May be raised when calling response.raise_for_status()
Bases: Exception
URL is improperly formed or cannot be parsed.
Bases: Exception
Attempted to lookup a cookie by name, but multiple cookies existed.
Can occur when calling response.cookies.get(...).
Bases: RuntimeError
The base class for stream exceptions.
The developer made an error in accessing the request stream in an invalid way.
Bases: StreamError
Attempted to read or stream content, but the content has already been streamed.
Bases: StreamError
Attempted to read or stream response content, but the request has been closed.
Bases: StreamError
Attempted to access streaming response content, without having called read().
Bases: StreamError
Attempted to access streaming request content, without having called read().