Package: httpz
httpz - A handy HTTP status code libraryInstallationpipinstallhttpzAPIGet an HTTP status code>>>HTTPStatusCodes.get("200")HTTPStatusCode(code=200, message=OK, description=The request has succeeded)HTTPStatusCodeobjects have several useful attributes:AttributeTypeExamplecodeint200messagestrOKdescriptionstrThe request has succeededcategorystrsuccessfulwebdavboolFalseexperimentalboolFalseFor example:>>>code=HTTPStatusCodes.get("100")>>>code.code100>>>code.message'Continue'>>>code.category'informational'>>>code.description'This interim response indicates that everything so far is OK and that the client should continue the request, or ignore the response if the request is already finished'Callingto_dict()on anHTTPStatusCodeobject will return a dict:>>>code=HTTPStatusCodes.get("200")>>>code.to_dict(){'description': 'The request has succeeded', 'code': 200, 'message': 'OK', 'webdav': False, 'category': 'successful'}Get a list ofHTTPStatusCodeobjects by category>>>HTTPStatusCodes.get_category("informational")[HTTPStatusCode(code=100, message=Continue, description=This interim response indicates that everything so far is OK and that the client should continue the request, or ignore the response if the request is already finished), HTTPStatusCode(code=101, message=Switching Protocol, description=This code is sent in response toan Upgrade request header from the client, and indicates the protocol the server is switching to), HTTPStatusCode(code=102, message=Processing, description=This code indicates that the server has received and is processing the request, but no response is available yet), HTTPStatusCode(code=103, message=Early Hints, description=This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response)]Categories:informational- 100 rangesuccessful- 200 rangeredirection- 300 rangeclient_error- 400 rangeserver_error- 500 rangeAn enum of categories is also available:>>>fromhttpzimportHTTPStatusCodeCategory>>>HTTPStatusCodeCategory.CLIENT_ERROR<HTTPStatusCodeCategory.CLIENT_ERROR: 'client_error'>>>>HTTPStatusCodeCategory.CLIENT_ERROR.value'client_error'An ordered list of allHTTPStatusCodeobjects (from low to high) can be obtained with:>>>fromhttpzimportHTTPStatusCodes>>>all_codes=HTTPStatusCodes.get_all()>>>forstatus_codeinall_codes:...print(status_code.code,status_code.message)100 Continue101 Switching Protocol102 Processing103 Early Hints200 OK201 Created202 Accepted203 Non-Authoritative Information204 No Content205 Reset Content206 Partial Content207 Multi-Status208 Already Reported226 IM Used300 Multiple Choice301 Moved Permanently302 Found303 See Other304 Not Modified305 Use Proxy306 Unused307 Temporary Redirect308 Permanent Redirect400 Bad Request401 Unauthorized402 Payment Required403 Forbidden404 Not Found405 Method Not Allowed406 Not Acceptable407 Proxy Authentication Required408 Request Timeout409 Conflict410 Gone411 Length Required412 Precondition Failed413 Payload Too Large414 URI Too Long415 Unsupported Media Type416 Range Not Satisfiable417 Expectation Failed418 I'm a teapot421 Misdirected Request422 Unprocessable Entity423 Locked424 Failed Dependency425 Too Early426 Upgrade Required428 Precondition Required429 Too Many Requests431 Request Header Fields Too Large451 Unavailable For Legal Reasons500 Internal Server Error501 Not Implemented502 Bad Gateway503 Service Unavailable504 Gateway Timeout505 HTTP Version Not Supported506 Variant Also Negotiates507 Insufficient Storage508 Loop Detected510 Not Extended511 Network Authentication Required