http — HTTP modules

소스 코드: Lib/http/__init__.py


http는 하이퍼텍스트 전송 프로토콜로 작업 하기 위한 여러 모듈을 수집하는 패키지입니다:

  • http.client는 저수준 HTTP 프로토콜 클라이언트입니다. 고수준의 URL 열기는 urllib.request를 사용합니다

  • http.serversocketserver에 기반을 둔 기본적인 HTTP 서버 클래스를 포함합니다

  • http.cookies는 쿠키를 사용하여 상태 관리를 구현하는 유틸리티가 있습니다

  • http.cookiejar는 쿠키의 지속성을 제공합니다

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

class http.HTTPStatus

Added in version 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 상태 코드

Supported, IANA-registered status codes available in http.HTTPStatus are:

코드

열거 이름

세부 사항

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

힌트를 나타내는 HTTP 상태 코드 RFC 8297

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 바인딩 확장 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

403

FORBIDDEN

HTTP Semantics RFC 9110, Section 15.5.4

404

NOT_FOUND

HTTP Semantics RFC 9110, Section 15.5.5

405

METHOD_NOT_ALLOWED

HTTP Semantics RFC 9110, Section 15.5.6

406

NOT_ACCEPTABLE

HTTP Semantics RFC 9110, Section 15.5.7

407

PROXY_AUTHENTICATION_REQUIRED

HTTP Semantics RFC 9110, Section 15.5.8

408

REQUEST_TIMEOUT

HTTP Semantics RFC 9110, Section 15.5.9

409

CONFLICT

HTTP Semantics RFC 9110, Section 15.5.10

410

GONE

HTTP Semantics RFC 9110, Section 15.5.11

411

LENGTH_REQUIRED

HTTP Semantics RFC 9110, Section 15.5.12

412

PRECONDITION_FAILED

HTTP Semantics RFC 9110, Section 15.5.13

413

CONTENT_TOO_LARGE

HTTP Semantics RFC 9110, Section 15.5.14

414

URI_TOO_LONG

HTTP Semantics RFC 9110, Section 15.5.15

415

UNSUPPORTED_MEDIA_TYPE

HTTP Semantics RFC 9110, Section 15.5.16

416

RANGE_NOT_SATISFIABLE

HTTP Semantics RFC 9110, Section 15.5.17

417

EXPECTATION_FAILED

HTTP Semantics RFC 9110, Section 15.5.18

418

IM_A_TEAPOT

HTCPCP/1.0 RFC 2324, 섹션 2.3.2

421

MISDIRECTED_REQUEST

HTTP Semantics RFC 9110, Section 15.5.20

422

UNPROCESSABLE_CONTENT

HTTP Semantics RFC 9110, Section 15.5.21

423

LOCKED

WebDAV RFC 4918, 섹션 11.3

424

FAILED_DEPENDENCY

WebDAV RFC 4918, 섹션 11.4

425

TOO_EARLY

HTTP에서 초기 데이터(Early Data) 사용 RFC 8470

426

UPGRADE_REQUIRED

HTTP Semantics RFC 9110, Section 15.5.22

428

PRECONDITION_REQUIRED

추가 HTTP 상태 코드 RFC 6585

429

TOO_MANY_REQUESTS

추가 HTTP 상태 코드 RFC 6585

431

REQUEST_HEADER_FIELDS_TOO_LARGE

추가 HTTP 상태 코드 RFC 6585

451

UNAVAILABLE_FOR_LEGAL_REASONS

법적 장애를 보고하는 HTTP 상태 코드 RFC 7725

500

INTERNAL_SERVER_ERROR

HTTP Semantics RFC 9110, Section 15.6.1

501

NOT_IMPLEMENTED

HTTP Semantics RFC 9110, Section 15.6.2

502

BAD_GATEWAY

HTTP Semantics RFC 9110, Section 15.6.3

503

SERVICE_UNAVAILABLE

HTTP Semantics RFC 9110, Section 15.6.4

504

GATEWAY_TIMEOUT

HTTP Semantics RFC 9110, Section 15.6.5

505

HTTP_VERSION_NOT_SUPPORTED

HTTP Semantics RFC 9110, Section 15.6.6

506

VARIANT_ALSO_NEGOTIATES

HTTP의 투명한 콘텐츠 협상 RFC 2295, 섹션 8.1 (실험적)

507

INSUFFICIENT_STORAGE

WebDAV RFC 4918, 섹션 11.5

508

LOOP_DETECTED

WebDAV 바인딩 확장 RFC 5842, 섹션 7.2 (실험적)

510

NOT_EXTENDED

HTTP 확장 프레임워크 RFC 2774, 섹션 7 (실험적)

511

NETWORK_AUTHENTICATION_REQUIRED

추가 HTTP 상태 코드 RFC 6585, 섹션 6

이전 버전과의 호환성을 유지하기 위해 열거값은 http.client 모듈에 상수 형태로도 있습니다. 열거명과 상수명은 동일합니다 (즉, http.HTTPStatus.OKhttp.client.OK로도 사용 가능합니다).

버전 3.7에서 변경: 421 MISDIRECTED_REQUEST 상태 코드 추가.

Added in version 3.8: 451 UNAVAILABLE_FOR_LEGAL_REASONS 상태 코드가 추가.

Added in version 3.9: 103 EARLY_HINTS, 418 IM_A_TEAPOT425 TOO_EARLY 상태 코드가 추가되었습니다.

버전 3.13에서 변경: Implemented RFC9110 naming for status constants. Old constant names are preserved for backwards compatibility.

HTTP status category

Added in version 3.12.

The enum values have several properties to indicate the HTTP status category:

Property

Indicates that

세부 사항

is_informational

100 <= status <= 199

HTTP Semantics RFC 9110, Section 15

is_success

200 <= status <= 299

HTTP Semantics RFC 9110, Section 15

is_redirection

300 <= status <= 399

HTTP Semantics RFC 9110, Section 15

is_client_error

400 <= status <= 499

HTTP Semantics RFC 9110, Section 15

is_server_error

500 <= status <= 599

HTTP Semantics RFC 9110, Section 15

사용법:

>>> from http import HTTPStatus
>>> HTTPStatus.OK.is_success
True
>>> HTTPStatus.OK.is_client_error
False
class http.HTTPMethod

Added in version 3.11.

A subclass of enum.StrEnum that defines a set of HTTP methods and descriptions written in English.

사용법:

>>> 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

Supported, IANA-registered methods available in http.HTTPMethod are:

Method

열거 이름

세부 사항

GET

GET

HTTP Semantics RFC 9110, Section 9.3.1

HEAD

HEAD

HTTP Semantics RFC 9110, Section 9.3.2

POST

POST

HTTP Semantics RFC 9110, Section 9.3.3

PUT

PUT

HTTP Semantics RFC 9110, Section 9.3.4

DELETE

DELETE

HTTP Semantics RFC 9110, Section 9.3.5

CONNECT

CONNECT

HTTP Semantics RFC 9110, Section 9.3.6

OPTIONS

OPTIONS

HTTP Semantics RFC 9110, Section 9.3.7

TRACE

TRACE

HTTP Semantics RFC 9110, Section 9.3.8

PATCH

PATCH

HTTP/1.1 RFC 5789