http.status
import http
httpexposes this ashttp.status, soimport httpis enough and the names are called ashttp.status.*.import http.statusreaches the same definitions directly.
The HTTP status codes registered with IANA, their canonical reason phrases, and a handful of predicates for asking what class a code belongs to.
The names are the constants; reason() turns a code into the phrase a
response line carries.
import http
echo http.status.NOT_FOUND # 404
echo http.status.reason(404) # Not Found
echo http.status.is_redirect(308) # true
Constants
CONTINUE
http.status.CONTINUE: int = 100
100 Continue. The client may proceed to send the request body it
announced with an Expect: 100-continue header.
SWITCHING_PROTOCOLS
http.status.SWITCHING_PROTOCOLS: int = 101
101 Switching Protocols. The server has accepted an Upgrade request;
everything after the response head speaks the new protocol. This is how
a WebSocket handshake completes.
PROCESSING
http.status.PROCESSING: int = 102
102 Processing (WebDAV, RFC 2518). An interim response telling a client the request is still being worked on.
EARLY_HINTS
http.status.EARLY_HINTS: int = 103
103 Early Hints (RFC 8297). Carries Link headers the client can act on
(preload, preconnect) before the final response arrives.
OK
http.status.OK: int = 200
200 OK.
CREATED
http.status.CREATED: int = 201
201 Created. A new resource exists; Location names it.
ACCEPTED
http.status.ACCEPTED: int = 202
202 Accepted. The request was valid and queued, but not acted on yet, and may still ultimately fail.
NON_AUTHORITATIVE_INFORMATION
http.status.NON_AUTHORITATIVE_INFORMATION: int = 203
203 Non-Authoritative Information. A transforming proxy modified the origin server’s response.
NO_CONTENT
http.status.NO_CONTENT: int = 204
204 No Content. Success, and deliberately no body. A response with this
status must never carry Content-Length or a body.
RESET_CONTENT
http.status.RESET_CONTENT: int = 205
205 Reset Content. Success; the client should reset the document view that sent the request.
PARTIAL_CONTENT
http.status.PARTIAL_CONTENT: int = 206
206 Partial Content. The body is the byte range(s) the request’s Range
header asked for.
MULTI_STATUS
http.status.MULTI_STATUS: int = 207
207 Multi-Status (WebDAV, RFC 4918). The body is an XML document carrying a separate status per sub-request.
ALREADY_REPORTED
http.status.ALREADY_REPORTED: int = 208
208 Already Reported (WebDAV, RFC 5842).
IM_USED
http.status.IM_USED: int = 226
226 IM Used (RFC 3229). The response is the result of applying one or more instance manipulations to the current resource.
MULTIPLE_CHOICES
http.status.MULTIPLE_CHOICES: int = 300
300 Multiple Choices.
MOVED_PERMANENTLY
http.status.MOVED_PERMANENTLY: int = 301
301 Moved Permanently. Clients and caches may rewrite the request method
to GET when following this, which is why 308 exists.
FOUND
http.status.FOUND: int = 302
302 Found. Historically (and still, in practice) followed by rewriting the method to GET.
SEE_OTHER
http.status.SEE_OTHER: int = 303
303 See Other. Follow with GET, always. This is the correct answer to a POST that should not be re-submitted on refresh.
NOT_MODIFIED
http.status.NOT_MODIFIED: int = 304
304 Not Modified. The cached representation the client already holds is still fresh. Carries no body.
USE_PROXY
http.status.USE_PROXY: int = 305
305 Use Proxy. Deprecated; clients are required to ignore it.
TEMPORARY_REDIRECT
http.status.TEMPORARY_REDIRECT: int = 307
307 Temporary Redirect. Like 302, but the method and body must be
preserved when following.
PERMANENT_REDIRECT
http.status.PERMANENT_REDIRECT: int = 308
308 Permanent Redirect. Like 301, but the method and body must be
preserved when following.
BAD_REQUEST
http.status.BAD_REQUEST: int = 400
400 Bad Request. The message could not be understood - malformed syntax, invalid framing, a header the server refuses to guess at.
UNAUTHORIZED
http.status.UNAUTHORIZED: int = 401
401 Unauthorized. Authentication is required or was rejected. A response
with this status must carry WWW-Authenticate.
PAYMENT_REQUIRED
http.status.PAYMENT_REQUIRED: int = 402
402 Payment Required.
FORBIDDEN
http.status.FORBIDDEN: int = 403
403 Forbidden. Understood and refused; re-authenticating won’t help. Use
401 when it would.
NOT_FOUND
http.status.NOT_FOUND: int = 404
404 Not Found.
METHOD_NOT_ALLOWED
http.status.METHOD_NOT_ALLOWED: int = 405
405 Method Not Allowed. The path exists but not for this method. A
response with this status must carry Allow.
NOT_ACCEPTABLE
http.status.NOT_ACCEPTABLE: int = 406
406 Not Acceptable. Nothing the server can produce matches the request’s
Accept headers.
PROXY_AUTHENTICATION_REQUIRED
http.status.PROXY_AUTHENTICATION_REQUIRED: int = 407
407 Proxy Authentication Required.
REQUEST_TIMEOUT
http.status.REQUEST_TIMEOUT: int = 408
408 Request Timeout. The client took too long to send a complete request.
CONFLICT
http.status.CONFLICT: int = 409
409 Conflict. The request conflicts with the current state of the resource.
GONE
http.status.GONE: int = 410
410 Gone. Like 404, but deliberately permanent.
LENGTH_REQUIRED
http.status.LENGTH_REQUIRED: int = 411
411 Length Required.
PRECONDITION_FAILED
http.status.PRECONDITION_FAILED: int = 412
412 Precondition Failed. A conditional header (If-Match,
If-Unmodified-Since, …) did not hold.
CONTENT_TOO_LARGE
http.status.CONTENT_TOO_LARGE: int = 413
413 Content Too Large. The body exceeds what the server will accept.
URI_TOO_LONG
http.status.URI_TOO_LONG: int = 414
414 URI Too Long.
UNSUPPORTED_MEDIA_TYPE
http.status.UNSUPPORTED_MEDIA_TYPE: int = 415
415 Unsupported Media Type. The body’s Content-Type isn’t one this
resource handles.
RANGE_NOT_SATISFIABLE
http.status.RANGE_NOT_SATISFIABLE: int = 416
416 Range Not Satisfiable. None of the ranges asked for overlap the resource.
EXPECTATION_FAILED
http.status.EXPECTATION_FAILED: int = 417
417 Expectation Failed. The request’s Expect header names something
the server cannot do.
IM_A_TEAPOT
http.status.IM_A_TEAPOT: int = 418
418 I’m a teapot (RFC 2324). Reserved, and not to be taken seriously, but registered often enough to be worth naming.
MISDIRECTED_REQUEST
http.status.MISDIRECTED_REQUEST: int = 421
421 Misdirected Request. The connection this request arrived on cannot serve the authority it names. Relevant to HTTP/2 connection coalescing.
UNPROCESSABLE_CONTENT
http.status.UNPROCESSABLE_CONTENT: int = 422
422 Unprocessable Content. Syntactically fine, semantically impossible - the usual answer to a validation failure.
LOCKED
http.status.LOCKED: int = 423
423 Locked (WebDAV, RFC 4918).
FAILED_DEPENDENCY
http.status.FAILED_DEPENDENCY: int = 424
424 Failed Dependency (WebDAV, RFC 4918).
TOO_EARLY
http.status.TOO_EARLY: int = 425
425 Too Early (RFC 8470). The server won’t risk processing a request that arrived in TLS early data.
UPGRADE_REQUIRED
http.status.UPGRADE_REQUIRED: int = 426
426 Upgrade Required. Carries an Upgrade header naming what the client
must switch to.
PRECONDITION_REQUIRED
http.status.PRECONDITION_REQUIRED: int = 428
428 Precondition Required (RFC 6585). The server insists the request be conditional, to avoid a lost update.
TOO_MANY_REQUESTS
http.status.TOO_MANY_REQUESTS: int = 429
429 Too Many Requests (RFC 6585). Rate limited; Retry-After says for
how long.
REQUEST_HEADER_FIELDS_TOO_LARGE
http.status.REQUEST_HEADER_FIELDS_TOO_LARGE: int = 431
431 Request Header Fields Too Large (RFC 6585).
UNAVAILABLE_FOR_LEGAL_REASONS
http.status.UNAVAILABLE_FOR_LEGAL_REASONS: int = 451
451 Unavailable For Legal Reasons (RFC 7725).
INTERNAL_SERVER_ERROR
http.status.INTERNAL_SERVER_ERROR: int = 500
500 Internal Server Error.
NOT_IMPLEMENTED
http.status.NOT_IMPLEMENTED: int = 501
501 Not Implemented. The server does not recognise the method at all -
not to be confused with 405, which is per-resource.
BAD_GATEWAY
http.status.BAD_GATEWAY: int = 502
502 Bad Gateway. An upstream this server proxies to returned something invalid.
SERVICE_UNAVAILABLE
http.status.SERVICE_UNAVAILABLE: int = 503
503 Service Unavailable. Temporary, by definition; pair it with
Retry-After.
GATEWAY_TIMEOUT
http.status.GATEWAY_TIMEOUT: int = 504
504 Gateway Timeout. An upstream did not answer in time.
HTTP_VERSION_NOT_SUPPORTED
http.status.HTTP_VERSION_NOT_SUPPORTED: int = 505
505 HTTP Version Not Supported.
VARIANT_ALSO_NEGOTIATES
http.status.VARIANT_ALSO_NEGOTIATES: int = 506
506 Variant Also Negotiates (RFC 2295).
INSUFFICIENT_STORAGE
http.status.INSUFFICIENT_STORAGE: int = 507
507 Insufficient Storage (WebDAV, RFC 4918).
LOOP_DETECTED
http.status.LOOP_DETECTED: int = 508
508 Loop Detected (WebDAV, RFC 5842).
NOT_EXTENDED
http.status.NOT_EXTENDED: int = 510
510 Not Extended (RFC 2774).
NETWORK_AUTHENTICATION_REQUIRED
http.status.NETWORK_AUTHENTICATION_REQUIRED: int = 511
511 Network Authentication Required (RFC 6585). The captive-portal status.
Functions
reason()
http.status.reason(code: int) -> string
The canonical reason phrase for code, e.g. 'Not Found' for 404.
An unregistered code is still perfectly legal on the wire - a client is
required to treat it as the generic x00 of its class - so rather than
failing, this falls back to the class name ('Informational',
'Success', 'Redirection', 'Client Error', 'Server Error'), or
'Unknown' for a code outside 100-599.
Parameters
code(int)
Returns string
is_registered()
http.status.is_registered(code: int) -> bool
Whether code is a registered status code with a canonical reason
phrase of its own.
Parameters
code(int)
Returns bool
is_informational()
http.status.is_informational(code: int) -> bool
Whether code is a 1xx interim status. These are consumed by the
protocol layer and never surface as the final response.
Parameters
code(int)
Returns bool
is_success()
http.status.is_success(code: int) -> bool
Whether code is a 2xx success status.
Parameters
code(int)
Returns bool
is_redirect()
http.status.is_redirect(code: int) -> bool
Whether code is a 3xx redirection status.
Parameters
code(int)
Returns bool
is_client_error()
http.status.is_client_error(code: int) -> bool
Whether code is a 4xx client error.
Parameters
code(int)
Returns bool
is_server_error()
http.status.is_server_error(code: int) -> bool
Whether code is a 5xx server error.
Parameters
code(int)
Returns bool
is_error()
http.status.is_error(code: int) -> bool
Whether code is any kind of error, client or server.
Parameters
code(int)
Returns bool
is_bodiless()
http.status.is_bodiless(code: int) -> bool
Whether a response carrying code is defined to have no body at all,
regardless of what headers say. RFC 9110 puts 1xx, 204 and 304 in
this category, and framing a body onto any of them is a protocol
violation rather than a stylistic choice.
Parameters
code(int)
Returns bool
preserves_method()
http.status.preserves_method(code: int) -> bool
Whether a redirect with code must keep the original method and body
when followed. True for 307 and 308; 301, 302 and 303 are all
conventionally rewritten to GET.
Parameters
code(int)
Returns bool
2026, Richard Ore and Zuri contributors