21.11.http — HTTP modules

Source code:Lib/http/__init__.py


http is a package that collects several modules for working with theHyperText Transfer Protocol:

http is also a module that defines a number of HTTP status codes andassociated messages through thehttp.HTTPStatus enum:

classhttp.HTTPStatus

New in version 3.5.

A subclass ofenum.IntEnum that defines a set of HTTP status codes,reason phrases and long descriptions written in English.

Usage:

>>>fromhttpimportHTTPStatus>>>HTTPStatus.OK<HTTPStatus.OK: 200>>>>HTTPStatus.OK==200True>>>http.HTTPStatus.OK.value200>>>HTTPStatus.OK.phrase'OK'>>>HTTPStatus.OK.description'Request fulfilled, document follows'>>>list(HTTPStatus)[<HTTPStatus.CONTINUE: 100>, <HTTPStatus.SWITCHING_PROTOCOLS: 101>, ...]

21.11.1. HTTP status codes

Supported,IANA-registeredstatus codes available inhttp.HTTPStatus are:

CodeEnum NameDetails
100CONTINUEHTTP/1.1RFC 7231, Section 6.2.1
101SWITCHING_PROTOCOLSHTTP/1.1RFC 7231, Section 6.2.2
102PROCESSINGWebDAVRFC 2518, Section 10.1
200OKHTTP/1.1RFC 7231, Section 6.3.1
201CREATEDHTTP/1.1RFC 7231, Section 6.3.2
202ACCEPTEDHTTP/1.1RFC 7231, Section 6.3.3
203NON_AUTHORITATIVE_INFORMATIONHTTP/1.1RFC 7231, Section 6.3.4
204NO_CONTENTHTTP/1.1RFC 7231, Section 6.3.5
205RESET_CONTENTHTTP/1.1RFC 7231, Section 6.3.6
206PARTIAL_CONTENTHTTP/1.1RFC 7233, Section 4.1
207MULTI_STATUSWebDAVRFC 4918, Section 11.1
208ALREADY_REPORTEDWebDAV Binding ExtensionsRFC 5842, Section 7.1 (Experimental)
226IM_USEDDelta Encoding in HTTPRFC 3229, Section 10.4.1
300MULTIPLE_CHOICESHTTP/1.1RFC 7231, Section 6.4.1
301MOVED_PERMANENTLYHTTP/1.1RFC 7231, Section 6.4.2
302FOUNDHTTP/1.1RFC 7231, Section 6.4.3
303SEE_OTHERHTTP/1.1RFC 7231, Section 6.4.4
304NOT_MODIFIEDHTTP/1.1RFC 7232, Section 4.1
305USE_PROXYHTTP/1.1RFC 7231, Section 6.4.5
307TEMPORARY_REDIRECTHTTP/1.1RFC 7231, Section 6.4.7
308PERMANENT_REDIRECTPermanent RedirectRFC 7238, Section 3 (Experimental)
400BAD_REQUESTHTTP/1.1RFC 7231, Section 6.5.1
401UNAUTHORIZEDHTTP/1.1 AuthenticationRFC 7235, Section 3.1
402PAYMENT_REQUIREDHTTP/1.1RFC 7231, Section 6.5.2
403FORBIDDENHTTP/1.1RFC 7231, Section 6.5.3
404NOT_FOUNDHTTP/1.1RFC 7231, Section 6.5.4
405METHOD_NOT_ALLOWEDHTTP/1.1RFC 7231, Section 6.5.5
406NOT_ACCEPTABLEHTTP/1.1RFC 7231, Section 6.5.6
407PROXY_AUTHENTICATION_REQUIREDHTTP/1.1 AuthenticationRFC 7235, Section 3.2
408REQUEST_TIMEOUTHTTP/1.1RFC 7231, Section 6.5.7
409CONFLICTHTTP/1.1RFC 7231, Section 6.5.8
410GONEHTTP/1.1RFC 7231, Section 6.5.9
411LENGTH_REQUIREDHTTP/1.1RFC 7231, Section 6.5.10
412PRECONDITION_FAILEDHTTP/1.1RFC 7232, Section 4.2
413REQUEST_ENTITY_TOO_LARGEHTTP/1.1RFC 7231, Section 6.5.11
414REQUEST_URI_TOO_LONGHTTP/1.1RFC 7231, Section 6.5.12
415UNSUPPORTED_MEDIA_TYPEHTTP/1.1RFC 7231, Section 6.5.13
416REQUEST_RANGE_NOT_SATISFIABLEHTTP/1.1 Range RequestsRFC 7233, Section 4.4
417EXPECTATION_FAILEDHTTP/1.1RFC 7231, Section 6.5.14
422UNPROCESSABLE_ENTITYWebDAVRFC 4918, Section 11.2
423LOCKEDWebDAVRFC 4918, Section 11.3
424FAILED_DEPENDENCYWebDAVRFC 4918, Section 11.4
426UPGRADE_REQUIREDHTTP/1.1RFC 7231, Section 6.5.15
428PRECONDITION_REQUIREDAdditional HTTP Status CodesRFC 6585
429TOO_MANY_REQUESTSAdditional HTTP Status CodesRFC 6585
431REQUEST_HEADER_FIELDS_TOO_LARGEAdditional HTTP Status CodesRFC 6585
500INTERNAL_SERVER_ERRORHTTP/1.1RFC 7231, Section 6.6.1
501NOT_IMPLEMENTEDHTTP/1.1RFC 7231, Section 6.6.2
502BAD_GATEWAYHTTP/1.1RFC 7231, Section 6.6.3
503SERVICE_UNAVAILABLEHTTP/1.1RFC 7231, Section 6.6.4
504GATEWAY_TIMEOUTHTTP/1.1RFC 7231, Section 6.6.5
505HTTP_VERSION_NOT_SUPPORTEDHTTP/1.1RFC 7231, Section 6.6.6
506VARIANT_ALSO_NEGOTIATESTransparent Content Negotiation in HTTPRFC 2295, Section 8.1 (Experimental)
507INSUFFICIENT_STORAGEWebDAVRFC 4918, Section 11.5
508LOOP_DETECTEDWebDAV Binding ExtensionsRFC 5842, Section 7.2 (Experimental)
510NOT_EXTENDEDAn HTTP Extension FrameworkRFC 2774, Section 7 (Experimental)
511NETWORK_AUTHENTICATION_REQUIREDAdditional HTTP Status CodesRFC 6585, Section 6

In order to preserve backwards compatibility, enum values are also presentin thehttp.client module in the form of constants. The enum name isequal to the constant name (i.e.http.HTTPStatus.OK is also available ashttp.client.OK).