HTTP状态代码utils
httpz的Python项目详细描述
httpz—一个方便的HTTP状态代码库
安装
pip install httpz
API
获取HTTP状态代码
^{pr2}$HTTPStatusCode
对象有几个有用的属性:
Attribute | Type | Example |
---|---|---|
^{ | ^{ | 200 |
^{ | ^{ | OK |
^{ | ^{ | The request has succeeded |
^{ | ^{ | successful |
^{ | ^{ | ^{ |
^{ | ^{ | ^{ |
例如:
>>> 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'
对HTTPStatusCode
对象调用to_dict()
将返回dict:
>>> code=HTTPStatusCodes.get("200")>>> code.to_dict(){'description': 'The request has succeeded', 'code': 200, 'message': 'OK', 'webdav': False, 'category': 'successful'}
按类别获取HTTPStatusCode
对象的列表
>>> 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)]
类别:
informational
-100范围successful
-200范围redirection
-300范围client_error
-400范围server_error
-500范围
类别的枚举也可用:
>>> fromhttpzimportHTTPStatusCodeCategory>>> HTTPStatusCodeCategory.CLIENT_ERROR<HTTPStatusCodeCategory.CLIENT_ERROR: 'client_error'>>>> HTTPStatusCodeCategory.CLIENT_ERROR.value'client_error'
所有HTTPStatusCode
对象的有序列表(从低到高)可以通过以下方式获得:
>>> 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
- 项目
标签: