Usage
Helper Functions
The status module includes helper functions for testing if a status code is in a given range.is_informational(code)
Tests if status code is in the 1xx range (100-199).is_success(code)
Tests if status code is in the 2xx range (200-299).is_redirect(code)
Tests if status code is in the 3xx range (300-399).is_client_error(code)
Tests if status code is in the 4xx range (400-499).is_server_error(code)
Tests if status code is in the 5xx range (500-599).Example: Testing Response Status
Status Code Constants
Informational - 1xx
Provisional responses indicating the request was received and is being processed.| Constant | Value | Description |
|---|---|---|
HTTP_100_CONTINUE | 100 | Continue |
HTTP_101_SWITCHING_PROTOCOLS | 101 | Switching Protocols |
HTTP_102_PROCESSING | 102 | Processing |
HTTP_103_EARLY_HINTS | 103 | Early Hints |
Successful - 2xx
The request was successfully received, understood, and accepted.| Constant | Value | Description |
|---|---|---|
HTTP_200_OK | 200 | OK |
HTTP_201_CREATED | 201 | Created |
HTTP_202_ACCEPTED | 202 | Accepted |
HTTP_203_NON_AUTHORITATIVE_INFORMATION | 203 | Non-Authoritative Information |
HTTP_204_NO_CONTENT | 204 | No Content |
HTTP_205_RESET_CONTENT | 205 | Reset Content |
HTTP_206_PARTIAL_CONTENT | 206 | Partial Content |
HTTP_207_MULTI_STATUS | 207 | Multi-Status |
HTTP_208_ALREADY_REPORTED | 208 | Already Reported |
HTTP_226_IM_USED | 226 | IM Used |
Redirection - 3xx
Further action needs to be taken to fulfill the request.| Constant | Value | Description |
|---|---|---|
HTTP_300_MULTIPLE_CHOICES | 300 | Multiple Choices |
HTTP_301_MOVED_PERMANENTLY | 301 | Moved Permanently |
HTTP_302_FOUND | 302 | Found |
HTTP_303_SEE_OTHER | 303 | See Other |
HTTP_304_NOT_MODIFIED | 304 | Not Modified |
HTTP_305_USE_PROXY | 305 | Use Proxy |
HTTP_306_RESERVED | 306 | Reserved |
HTTP_307_TEMPORARY_REDIRECT | 307 | Temporary Redirect |
HTTP_308_PERMANENT_REDIRECT | 308 | Permanent Redirect |
Client Error - 4xx
The request contains bad syntax or cannot be fulfilled due to a client error.| Constant | Value | Description |
|---|---|---|
HTTP_400_BAD_REQUEST | 400 | Bad Request |
HTTP_401_UNAUTHORIZED | 401 | Unauthorized |
HTTP_402_PAYMENT_REQUIRED | 402 | Payment Required |
HTTP_403_FORBIDDEN | 403 | Forbidden |
HTTP_404_NOT_FOUND | 404 | Not Found |
HTTP_405_METHOD_NOT_ALLOWED | 405 | Method Not Allowed |
HTTP_406_NOT_ACCEPTABLE | 406 | Not Acceptable |
HTTP_407_PROXY_AUTHENTICATION_REQUIRED | 407 | Proxy Authentication Required |
HTTP_408_REQUEST_TIMEOUT | 408 | Request Timeout |
HTTP_409_CONFLICT | 409 | Conflict |
HTTP_410_GONE | 410 | Gone |
HTTP_411_LENGTH_REQUIRED | 411 | Length Required |
HTTP_412_PRECONDITION_FAILED | 412 | Precondition Failed |
HTTP_413_REQUEST_ENTITY_TOO_LARGE | 413 | Request Entity Too Large |
HTTP_414_REQUEST_URI_TOO_LONG | 414 | Request-URI Too Long |
HTTP_415_UNSUPPORTED_MEDIA_TYPE | 415 | Unsupported Media Type |
HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE | 416 | Requested Range Not Satisfiable |
HTTP_417_EXPECTATION_FAILED | 417 | Expectation Failed |
HTTP_418_IM_A_TEAPOT | 418 | I’m a teapot |
HTTP_421_MISDIRECTED_REQUEST | 421 | Misdirected Request |
HTTP_422_UNPROCESSABLE_ENTITY | 422 | Unprocessable Entity |
HTTP_423_LOCKED | 423 | Locked |
HTTP_424_FAILED_DEPENDENCY | 424 | Failed Dependency |
HTTP_425_TOO_EARLY | 425 | Too Early |
HTTP_426_UPGRADE_REQUIRED | 426 | Upgrade Required |
HTTP_428_PRECONDITION_REQUIRED | 428 | Precondition Required |
HTTP_429_TOO_MANY_REQUESTS | 429 | Too Many Requests |
HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE | 431 | Request Header Fields Too Large |
HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS | 451 | Unavailable For Legal Reasons |
Server Error - 5xx
The server failed to fulfill an apparently valid request.| Constant | Value | Description |
|---|---|---|
HTTP_500_INTERNAL_SERVER_ERROR | 500 | Internal Server Error |
HTTP_501_NOT_IMPLEMENTED | 501 | Not Implemented |
HTTP_502_BAD_GATEWAY | 502 | Bad Gateway |
HTTP_503_SERVICE_UNAVAILABLE | 503 | Service Unavailable |
HTTP_504_GATEWAY_TIMEOUT | 504 | Gateway Timeout |
HTTP_505_HTTP_VERSION_NOT_SUPPORTED | 505 | HTTP Version Not Supported |
HTTP_506_VARIANT_ALSO_NEGOTIATES | 506 | Variant Also Negotiates |
HTTP_507_INSUFFICIENT_STORAGE | 507 | Insufficient Storage |
HTTP_508_LOOP_DETECTED | 508 | Loop Detected |
HTTP_509_BANDWIDTH_LIMIT_EXCEEDED | 509 | Bandwidth Limit Exceeded |
HTTP_510_NOT_EXTENDED | 510 | Not Extended |
HTTP_511_NETWORK_AUTHENTICATION_REQUIRED | 511 | Network Authentication Required |
Common Usage Patterns
Successful Operations
Client Errors
References
- RFC 2616 - HTTP/1.1 Status Code Definitions
- RFC 6585 - Additional HTTP Status Codes
- RFC 4918 - HTTP Extensions for WebDAV
See Also
- Response - Response class
- Exceptions - Exception classes that use these status codes
