HTTP状态代码utils

httpz的Python项目详细描述


httpz—一个方便的HTTP状态代码库

安装
pip install httpz

API

获取HTTP状态代码

^{pr2}$

HTTPStatusCode对象有几个有用的属性:

AttributeTypeExample
^{}^{}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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Javalog4j2。xml和log4j2test。eclipse中的xml   java映像未显示在surfaceview中   在Java中,能否在for之后立即放置if?   java调用构造函数的不同方式是什么?   java为什么不将其视为多重继承,而所有类都首先从对象类扩展,然后再扩展其他类   带有ms access的java不显示数据库结果   java Eclipse命令行URL参数切断https   java Android JNI回调似乎调用了一个随机方法   java Apache Camel处理XMLFile中声明的编码   java Bonita BPM不要等待Bonita的函数结束   布尔Java:构建逻辑表达式,然后验证它们   java在不使用QueryString的情况下将变量从一个网站页面传递到另一个网站页面   java ORA01861:文本与格式字符串不匹配   java字节[]字符串到C中的字符串#   java试图通过socket发送sqlite数据库文件   java如何使用命令行更改属性文件中的浏览器值以运行selenium测试用例