http
— HTTP modules¶
Source code: Lib/http/__init__.py
http
is a package that collects several modules for working with the HyperText Transfer Protocol:是一个收集多个模块以使用超文本传输协议的包:
http.client
is a low-level HTTP protocol client; for high-level URL opening use是低级HTTP协议客户端;对于高级URL打开,请使用urllib.request
urllib.request
http.server
contains basic HTTP server classes based on包含基于socketserver
socketserver
的基本HTTP服务器类http.cookies
has utilities for implementing state management with cookies具有使用cookie实现状态管理的实用程序http.cookiejar
provides persistence of cookies提供cookie的持久性
http
is also a module that defines a number of HTTP status codes and associated messages through the 也是一个通过http.HTTPStatus
enum:http.HTTPStatus
枚举定义多个HTTP状态代码和相关消息的模块:
-
class
http.
HTTPStatus
¶ -
New in version 3.5.版本3.5中新增。A subclass ofenum.IntEnum
that defines a set of HTTP status codes, reason phrases and long descriptions written in English.enum.IntEnum
的一个子类,定义了一组HTTP状态代码、原因短语和用英语编写的长描述。Usage:用法:>>> 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 status codes¶
Supported, IANA-registered status codes available in 支持,http.HTTPStatus
are:http.HTTPStatus
中可用的IANA注册状态代码为:
Code |
Enum Name |
Details |
---|---|---|
|
|
HTTP/1.1 RFC 7231, Section 6.2.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.2.2 |
|
|
WebDAV RFC 2518, Section 10.1 |
|
|
|
|
|
HTTP/1.1 RFC 7231, Section 6.3.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.3.6 |
|
|
HTTP/1.1 RFC 7233, Section 4.1 |
|
|
WebDAV RFC 4918, Section 11.1 |
|
|
|
|
|
|
|
|
HTTP/1.1 RFC 7231, Section 6.4.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.4 |
|
|
HTTP/1.1 RFC 7232, Section 4.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.4.7 |
|
|
Permanent Redirect RFC 7238, Section 3 (Experimental) |
|
|
HTTP/1.1 RFC 7231, Section 6.5.1 |
|
|
HTTP/1.1 Authentication RFC 7235, Section 3.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.6 |
|
|
HTTP/1.1 Authentication RFC 7235, Section 3.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.7 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.8 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.9 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.10 |
|
|
HTTP/1.1 RFC 7232, Section 4.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.11 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.12 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.13 |
|
|
HTTP/1.1 Range Requests RFC 7233, Section 4.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.14 |
|
|
HTCPCP/1.0 RFC 2324, Section 2.3.2 |
|
|
HTTP/2 RFC 7540, Section 9.1.2 |
|
|
WebDAV RFC 4918, Section 11.2 |
|
|
WebDAV RFC 4918, Section 11.3 |
|
|
WebDAV RFC 4918, Section 11.4 |
|
|
Using Early Data in HTTP RFC 8470 |
|
|
HTTP/1.1 RFC 7231, Section 6.5.15 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
Additional HTTP Status Codes RFC 6585 |
|
|
An HTTP Status Code to Report Legal Obstacles RFC 7725 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.1 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.2 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.3 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.4 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.5 |
|
|
HTTP/1.1 RFC 7231, Section 6.6.6 |
|
|
|
|
|
WebDAV RFC 4918, Section 11.5 |
|
|
WebDAV Binding Extensions RFC 5842, Section 7.2 (Experimental) |
|
|
An HTTP Extension Framework RFC 2774, Section 7 (Experimental) |
|
|
|
In order to preserve backwards compatibility, enum values are also present in the 为了保持向后兼容性,http.client
module in the form of constants. http.client
模块中还以常量的形式存在枚举值。The enum name is equal to the constant name (i.e. 枚举名称等于常量名称(即http.HTTPStatus.OK
is also available as http.client.OK
).http.HTTPStatus.OK
也可用作http.client.OK
)。
Changed in version 3.7:版本3.7中更改: Added 添加421 MISDIRECTED_REQUEST
status code.421 MISDIRECTED_REQUEST
状态代码。
New in version 3.8.版本3.8中新增。Added 添加451 UNAVAILABLE_FOR_LEGAL_REASONS
status code.451 UNAVAILABLE_FOR_LEGAL_REASONS
状态代码。
New in version 3.9.版本3.9中新增。Added 增加了103 EARLY_HINTS
, 418 IM_A_TEAPOT
and 425 TOO_EARLY
status codes.103 EARLY_HINTS
、418 IM_A_TEAPOT
和425 TOO_EARLY
状态代码。