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).
The exception hierarchy
- HTTPError
- RequestError
- TransportError
- TimeoutException
- ConnectTimeout
- ReadTimeout
- WriteTimeout
- PoolTimeout
- NetworkError
- ConnectError
- ReadError
- WriteError
- CloseError
- ProtocolError
- LocalProtocolError
- RemoteProtocolError
- ProxyError
- UnsupportedProtocol
- TimeoutException
- DecodingError
- TooManyRedirects
- TransportError
- HTTPStatusError
- RequestError
- InvalidURL
- CookieConflict
- StreamError
- StreamConsumed
- ResponseNotRead
- RequestNotRead
- StreamClosed
Exception classes
httpx2.HTTPError
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}")
httpx2.RequestError
httpx2.TransportError
httpx2.TimeoutException
httpx2.ConnectTimeout
httpx2.ReadTimeout
httpx2.WriteTimeout
httpx2.PoolTimeout
httpx2.NetworkError
Bases: TransportError
The base class for network-related errors.
An error occurred while interacting with the network.
httpx2.ConnectError
httpx2.ReadError
httpx2.WriteError
httpx2.CloseError
httpx2.ProtocolError
httpx2.LocalProtocolError
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().
httpx2.RemoteProtocolError
Bases: ProtocolError
The protocol was violated by the server.
For example, returning malformed HTTP.
httpx2.ProxyError
httpx2.UnsupportedProtocol
Bases: TransportError
Attempted to make a request to an unsupported protocol.
For example issuing a request to ftp://www.example.com.
httpx2.DecodingError
httpx2.TooManyRedirects
httpx2.HTTPStatusError
Bases: HTTPError
The response had an error HTTP status of 4xx or 5xx.
May be raised when calling response.raise_for_status()
httpx2.InvalidURL
httpx2.CookieConflict
Bases: Exception
Attempted to lookup a cookie by name, but multiple cookies existed.
Can occur when calling response.cookies.get(...).
httpx2.StreamError
Bases: RuntimeError
The base class for stream exceptions.
The developer made an error in accessing the request stream in an invalid way.