http.errors
import http
Everything here is re-exported by
http, soimport httpis enough and the names are called ashttp.*. Importinghttp.errorson its own works too and reaches the same definitions.
Every error the HTTP stack raises, under one root.
HttpError is that root, so a caller that only wants to know whether
the request failed can catch it and ignore the rest. The subclasses
separate the cases worth handling differently: a connection that never
opened, one that timed out, a response too large to accept, a redirect
loop, and a status the caller asked to be treated as an error.
Classes
HttpError
class http.HttpError < Error
Base class for every error the http module raises.
Catching HttpError catches everything this module can throw on its
own; the more specific subclasses below let a caller tell a connection
failure apart from a malformed response without matching on message
text.
- printable — has a
@to_string(), soechoandprint()show something useful
HttpError.to_string()
http.HttpError.to_string()
ProtocolError
class http.ProtocolError < HttpError
Raised when a peer sends something that isn’t a well-formed HTTP message: a broken request line or status line, a header field that doesn’t parse, an impossible framing combination, or a chunked body whose chunk sizes don’t add up.
A server answers these with 400 Bad Request and closes the connection,
since a stream whose framing is in doubt cannot safely be reused.
- printable — has a
@to_string(), soechoandprint()show something useful
ProtocolError.to_string()
http.ProtocolError.to_string()
ConnectionError
class http.ConnectionError < HttpError
Raised when a connection could not be established, or when an established connection failed or was closed before the message being read or written was complete.
- printable — has a
@to_string(), soechoandprint()show something useful
ConnectionError.to_string()
http.ConnectionError.to_string()
TimeoutError
class http.TimeoutError < HttpError
Raised when an operation exceeded its configured deadline: a connect, a read, a write, or the total time budget for a request.
- printable — has a
@to_string(), soechoandprint()show something useful
TimeoutError.to_string()
http.TimeoutError.to_string()
TooLargeError
class http.TooLargeError < HttpError
Raised when a message exceeds one of the configured size limits -
request line, header block, or body. Servers turn this into a 431 or
413 response rather than reading an unbounded amount of
attacker-controlled data into memory.
- printable — has a
@to_string(), soechoandprint()show something useful
TooLargeError.to_string()
http.TooLargeError.to_string()
TooManyRedirectsError
class http.TooManyRedirectsError < HttpError
Raised by the client when a redirect chain exceeds
HttpClient.max_redirects, which usually means the chain is a loop.
- printable — has a
@to_string(), soechoandprint()show something useful
TooManyRedirectsError.to_string()
http.TooManyRedirectsError.to_string()
StatusError
class http.StatusError < HttpError
Raised by HttpResponse.raise_for_status() when the response carries a
4xx or 5xx status. The response itself stays reachable through
response, so the body (which for an API is usually where the actual
explanation lives) isn’t lost.
- printable — has a
@to_string(), soechoandprint()show something useful
Fields
| Field | Type | Description |
|---|---|---|
response | HttpResponse | The response that carried the failing status. |
Constructor
http.StatusError(message, response)
StatusError.to_string()
http.StatusError.to_string()
UnsupportedProtocolError
class http.UnsupportedProtocolError < HttpError
Raised when a URL names a scheme this module cannot speak, or when a peer insists on a protocol version that was not offered.
- printable — has a
@to_string(), soechoandprint()show something useful
UnsupportedProtocolError.to_string()
http.UnsupportedProtocolError.to_string()
2026, Richard Ore and Zuri contributors