http
--- HTTP 模块¶
源代码: Lib/http/__init__.py
http
是一个包,它收集了多个用于处理超文本传输协议的模块:
http.client
是一个低层级的 HTTP 协议客户端;对于高层级的 URL 访问请使用urllib.request
http.server
包含基于socketserver
的基本 HTTP 服务类http.cookies
包含一些有用来实现通过 cookies 进行状态管理的工具http.cookiejar
提供了 cookies 的持久化
http
也是一个通过 http.HTTPStatus
枚举定义了一些 HTTP 状态码以及相关联消息的模块
-
class
http.
HTTPStatus
¶ 3.5 新版功能.
enum.IntEnum
的子类,它定义了组 HTTP 状态码,原理短语以及用英语书写的长描述文本。用法:
>>> from http import HTTPStatus >>> HTTPStatus.OK <HTTPStatus.OK: 200> >>> HTTPStatus.OK == 200 True >>> HTTPStatus.OK.value 200 >>> HTTPStatus.OK.phrase 'OK' >>> HTTPStatus.OK.description 'Request fulfilled, document follows' >>> list(HTTPStatus) [<HTTPStatus.CONTINUE: 100>, <HTTPStatus.SWITCHING_PROTOCOLS: 101>, ...]
HTTP 状态码¶
已支持并且已在 http.HTTPStatus
IANA 注册 的状态码有:
双字母代码 |
映射名 |
详情 |
---|---|---|
|
|
HTTP/1.1 RFC 7231, 6.2.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.2.2 节 |
|
|
WebDAV RFC 2518, 10.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.3.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.3.2 节 |
|
|
HTTP/1.1 RFC 7231, 6.3.3 节 |
|
|
HTTP/1.1 RFC 7231, 6.3.4 节 |
|
|
HTTP/1.1 RFC 7231, 6.3.5 节 |
|
|
HTTP/1.1 RFC 7231, 6.3.6 节 |
|
|
HTTP/1.1 RFC 7233, 4.1 节 |
|
|
WebDAV RFC 4918, 11.1 节 |
|
|
WebDAV Binding Extensions RFC 5842, 7.1 节(实验性) |
|
|
Delta Encoding in HTTP RFC 3229, 10.4.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.4.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.4.2 节 |
|
|
HTTP/1.1 RFC 7231, 6.4.3 节 |
|
|
HTTP/1.1 RFC 7231, 6.4.4 节 |
|
|
HTTP/1.1 RFC 7232, 4.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.4.5 节 |
|
|
HTTP/1.1 RFC 7231, 6.4.7 节 |
|
|
Permanent Redirect RFC 7238, Section 3 (Experimental) |
|
|
HTTP/1.1 RFC 7231, 6.5.1 节 |
|
|
HTTP/1.1 Authentication RFC 7235, 3.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.2 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.3 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.4 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.5 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.6 节 |
|
|
HTTP/1.1 Authentication RFC 7235, 3.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.7 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.8 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.9 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.10 节 |
|
|
HTTP/1.1 RFC 7232, 4.2 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.11 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.12 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.13 节 |
|
|
HTTP/1.1 Range Requests RFC 7233, 4.4 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.14 节 |
|
|
HTTP/2 RFC 7540, 9.1.2 节 |
|
|
WebDAV RFC 4918, 11.2 节 |
|
|
WebDAV RFC 4918, 11.3 节 |
|
|
WebDAV RFC 4918, 11.4 节 |
|
|
HTTP/1.1 RFC 7231, 6.5.15 节 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
HTTP 状态码用于报告法律障碍 RFC 7725 |
|
|
HTTP/1.1 RFC 7231, 6.6.1 节 |
|
|
HTTP/1.1 RFC 7231, 6.6.2 节 |
|
|
HTTP/1.1 RFC 7231, 6.6.3 节 |
|
|
HTTP/1.1 RFC 7231, 6.6.4 节 |
|
|
HTTP/1.1 RFC 7231, 6.6.5 节 |
|
|
HTTP/1.1 RFC 7231, 6.6.6 节 |
|
|
透明内容协商在: HTTP RFC 2295, 8.1 节(实验性) |
|
|
WebDAV RFC 4918, 11.5 节 |
|
|
WebDAV Binding Extensions RFC 5842, 7.2 节(实验性) |
|
|
WebDAV Binding Extensions RFC 5842, 7.2 节(实验性) |
|
|
Additional HTTP Status Codes RFC 6585, 6 节 |
为了保持向后兼容性,枚举值也以常量形式出现在 http.client
模块中,。 枚举名等于常量名 (例如 http.HTTPStatus.OK
也可以是 http.client.OK
)。
在 3.7 版更改: 添加了 421 MISDIRECTED_REQUEST
状态码。
3.8 新版功能: 添加了 451 UNAVAILABLE_FOR_LEGAL_REASONS
状态码。