http
--- HTTP モジュール群¶
ソースコード: Lib/http/__init__.py
http
パッケージはハイパーテキスト転送プロトコルを扱うための幾つかのモジュールを集めたものです:
http.client
は低水準のHTTPプロトコルのクライアントです。高水準の URL を開く操作にはurllib.request
を使ってくださいhttp.server
はsocketserver
をベースにした基礎的な HTTP サーバーを実装していますhttp.cookies
は cookie の状態管理を実装するためのユーティリティーを提供していますhttp.cookiejar
は cookie の永続化機能を提供しています
The http
module also defines the following enums that help you work with http related code:
- class http.HTTPStatus¶
バージョン 3.5 で追加.
一連の HTTP ステータスコード、理由の表現、英語で書かれた長い記述を定義した
enum.IntEnum
のサブクラスです。使い方:
>>> 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 に登録されたステータスコード <https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml>`_ は:
コード |
列挙名 |
詳細 |
---|---|---|
|
|
HTTP Semantics RFC 9110, Section 15.2.1 |
|
|
HTTP Semantics RFC 9110, Section 15.2.2 |
|
|
WebDAV RFC 2518, Section 10.1 |
|
|
An HTTP Status Code for Indicating Hints RFC 8297 |
|
|
HTTP Semantics RFC 9110, Section 15.3.1 |
|
|
HTTP Semantics RFC 9110, Section 15.3.2 |
|
|
HTTP Semantics RFC 9110, Section 15.3.3 |
|
|
HTTP Semantics RFC 9110, Section 15.3.4 |
|
|
HTTP Semantics RFC 9110, Section 15.3.5 |
|
|
HTTP Semantics RFC 9110, Section 15.3.6 |
|
|
HTTP Semantics RFC 9110, Section 15.3.7 |
|
|
WebDAV RFC 4918, Section 11.1 |
|
|
WebDAV Binding Extensions RFC 5842, Section 7.1 (Experimental) |
|
|
Delta Encoding in HTTP RFC 3229, Section 10.4.1 |
|
|
HTTP Semantics RFC 9110, Section 15.4.1 |
|
|
HTTP Semantics RFC 9110, Section 15.4.2 |
|
|
HTTP Semantics RFC 9110, Section 15.4.3 |
|
|
HTTP Semantics RFC 9110, Section 15.4.4 |
|
|
HTTP Semantics RFC 9110, Section 15.4.5 |
|
|
HTTP Semantics RFC 9110, Section 15.4.6 |
|
|
HTTP Semantics RFC 9110, Section 15.4.8 |
|
|
HTTP Semantics RFC 9110, Section 15.4.9 |
|
|
HTTP Semantics RFC 9110, Section 15.5.1 |
|
|
HTTP Semantics RFC 9110, Section 15.5.2 |
|
|
HTTP Semantics RFC 9110, Section 15.5.3 |
|
|
HTTP Semantics RFC 9110, Section 15.5.4 |
|
|
HTTP Semantics RFC 9110, Section 15.5.5 |
|
|
HTTP Semantics RFC 9110, Section 15.5.6 |
|
|
HTTP Semantics RFC 9110, Section 15.5.7 |
|
|
HTTP Semantics RFC 9110, Section 15.5.8 |
|
|
HTTP Semantics RFC 9110, Section 15.5.9 |
|
|
HTTP Semantics RFC 9110, Section 15.5.10 |
|
|
HTTP Semantics RFC 9110, Section 15.5.11 |
|
|
HTTP Semantics RFC 9110, Section 15.5.12 |
|
|
HTTP Semantics RFC 9110, Section 15.5.13 |
|
|
HTTP Semantics RFC 9110, Section 15.5.14 |
|
|
HTTP Semantics RFC 9110, Section 15.5.15 |
|
|
HTTP Semantics RFC 9110, Section 15.5.16 |
|
|
HTTP Semantics RFC 9110, Section 15.5.17 |
|
|
HTTP Semantics RFC 9110, Section 15.5.18 |
|
|
HTCPCP/1.0 RFC 2324, Section 2.3.2 |
|
|
HTTP Semantics RFC 9110, Section 15.5.20 |
|
|
HTTP Semantics RFC 9110, Section 15.5.21 |
|
|
WebDAV RFC 4918, Section 11.3 |
|
|
WebDAV RFC 4918, Section 11.4 |
|
|
Using Early Data in HTTP RFC 8470 |
|
|
HTTP Semantics RFC 9110, Section 15.5.22 |
|
|
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 Semantics RFC 9110, Section 15.6.1 |
|
|
HTTP Semantics RFC 9110, Section 15.6.2 |
|
|
HTTP Semantics RFC 9110, Section 15.6.3 |
|
|
HTTP Semantics RFC 9110, Section 15.6.4 |
|
|
HTTP Semantics RFC 9110, Section 15.6.5 |
|
|
HTTP Semantics RFC 9110, Section 15.6.6 |
|
|
Transparent Content Negotiation in HTTP RFC 2295, Section 8.1 (Experimental) |
|
|
WebDAV RFC 4918, Section 11.5 |
|
|
WebDAV Binding Extensions RFC 5842, Section 7.2 (Experimental) |
|
|
An HTTP Extension Framework RFC 2774, Section 7 (Experimental) |
|
|
Additional HTTP Status Codes RFC 6585, Section 6 |
後方互換性を保つために列挙値は http.client
にも定数という形で存在します。
列挙名は定数名と同じです (すなわち http.HTTPStatus.OK
は http.client.OK
としても利用可能です)。
バージョン 3.7 で変更: ステータスコード 421 MISDIRECTED_REQUEST
が追加されました。
バージョン 3.8 で追加: ステータスコード 451 UNAVAILABLE_FOR_LEGAL_REASONS
が追加されました。
バージョン 3.9 で追加: ステータスコード 103 EARLY_HINTS
, 418 IM_A_TEAPOT
, 425 TOO_EARLY
が追加されました。
バージョン 3.13 で変更: Implemented RFC9110 naming for status constants. Old constant names are preserved for backwards compatibility.
HTTP status category¶
バージョン 3.12 で追加.
The enum values have several properties to indicate the HTTP status category:
Property |
Indicates that |
詳細 |
---|---|---|
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
|
|
HTTP Semantics RFC 9110, Section 15 |
使い方:
>>> from http import HTTPStatus >>> HTTPStatus.OK.is_success True >>> HTTPStatus.OK.is_client_error False
- class http.HTTPMethod¶
バージョン 3.11 で追加.
一連の HTTP メソッド、英語で書かれた記述を定義した
enum.StrEnum
のサブクラスです。使い方:
>>> from http import HTTPMethod >>> >>> HTTPMethod.GET <HTTPMethod.GET> >>> HTTPMethod.GET == 'GET' True >>> HTTPMethod.GET.value 'GET' >>> HTTPMethod.GET.description 'Retrieve the target.' >>> list(HTTPMethod) [<HTTPMethod.CONNECT>, <HTTPMethod.DELETE>, <HTTPMethod.GET>, <HTTPMethod.HEAD>, <HTTPMethod.OPTIONS>, <HTTPMethod.PATCH>, <HTTPMethod.POST>, <HTTPMethod.PUT>, <HTTPMethod.TRACE>]
HTTP methods¶
http.HTTPMethod
で利用可能な、サポートされている、IANA に登録されたメソッド は:
メソッド |
列挙名 |
詳細 |
---|---|---|
|
|
HTTP Semantics RFC 9110, Section 9.3.1 |
|
|
HTTP Semantics RFC 9110, Section 9.3.2 |
|
|
HTTP Semantics RFC 9110, Section 9.3.3 |
|
|
HTTP Semantics RFC 9110, Section 9.3.4 |
|
|
HTTP Semantics RFC 9110, Section 9.3.5 |
|
|
HTTP Semantics RFC 9110, Section 9.3.6 |
|
|
HTTP Semantics RFC 9110, Section 9.3.7 |
|
|
HTTP Semantics RFC 9110, Section 9.3.8 |
|
|
HTTP/1.1 RFC 5789 |