http --- HTTP 模組

原始碼:Lib/http/__init__.py


http 是一個收集了多個用於處理超文本傳輸協定 (HyperText Transfer Protocol) 之模組 (module) 的套件:

The http module also defines the following enums that help you work with http related code:

class http.HTTPStatus

在 3.5 版被加入.

enum.IntEnum 的子類別,它定義了一組 HTTP 狀態碼、原理短語 (reason phrase) 以及英文長描述。

用法:

>>> from http import HTTPStatus
>>> HTTPStatus.OK
HTTPStatus.OK
>>> HTTPStatus.OK == 200
True
>>> HTTPStatus.OK.value
200
>>> HTTPStatus.OK.phrase
'OK'
>>> HTTPStatus.OK.description
'Request fulfilled, document follows'
>>> list(HTTPStatus)
[HTTPStatus.CONTINUE, HTTPStatus.SWITCHING_PROTOCOLS, ...]

HTTP 狀態碼

http.HTTPStatus 當中,已支援並且有於 IANA 註冊的狀態碼有:

狀態碼

列舉名稱

詳情

100

CONTINUE

HTTP Semantics RFC 9110, Section 15.2.1

101

SWITCHING_PROTOCOLS

HTTP Semantics RFC 9110, Section 15.2.2

102

PROCESSING

WebDAV RFC 2518,10.1 節

103

EARLY_HINTS

用於指定提示 (Indicating Hints) RFC 8297 的 HTTP 狀態碼

200

OK

HTTP Semantics RFC 9110, Section 15.3.1

201

CREATED

HTTP Semantics RFC 9110, Section 15.3.2

202

ACCEPTED

HTTP Semantics RFC 9110, Section 15.3.3

203

NON_AUTHORITATIVE_INFORMATION

HTTP Semantics RFC 9110, Section 15.3.4

204

NO_CONTENT

HTTP Semantics RFC 9110, Section 15.3.5

205

RESET_CONTENT

HTTP Semantics RFC 9110, Section 15.3.6

206

PARTIAL_CONTENT

HTTP Semantics RFC 9110, Section 15.3.7

207

MULTI_STATUS

WebDAV RFC 4918,11.1 節

208

ALREADY_REPORTED

WebDAV 繫結擴充 (Binding Extensions) RFC 5842,7.1 節(實驗性)

226

IM_USED

HTTP 中的差分編碼 RFC 3229,10.4.1 節

300

MULTIPLE_CHOICES

HTTP Semantics RFC 9110, Section 15.4.1

301

MOVED_PERMANENTLY

HTTP Semantics RFC 9110, Section 15.4.2

302

FOUND

HTTP Semantics RFC 9110, Section 15.4.3

303

SEE_OTHER

HTTP Semantics RFC 9110, Section 15.4.4

304

NOT_MODIFIED

HTTP Semantics RFC 9110, Section 15.4.5

305

USE_PROXY

HTTP Semantics RFC 9110, Section 15.4.6

307

TEMPORARY_REDIRECT

HTTP Semantics RFC 9110, Section 15.4.8

308

PERMANENT_REDIRECT

HTTP Semantics RFC 9110, Section 15.4.9

400

BAD_REQUEST

HTTP Semantics RFC 9110, Section 15.5.1

401

UNAUTHORIZED

HTTP Semantics RFC 9110, Section 15.5.2

402

PAYMENT_REQUIRED

HTTP Semantics RFC 9110, Section 15.5.3