Python Glossary Русский

Python 3.11+http.clientterm

http.HTTPMethod

status codes and methods

An enumeration of HTTP methods (GET, POST, PUT, PATCH…) with string values and a short description of each method.

Syntax

HTTPMethod.GET · HTTPMethod('POST').description

The values are upper-case strings and HTTPMethod.GET == 'GET' is true, but lookup by value is case-sensitive: HTTPMethod('get') raises ValueError. So normalise a request method with upper() first. The enum exists only since 3.11 — code that must run on 3.10 keeps using plain strings.

Examples

from http import HTTPMethod
print(HTTPMethod.GET == 'GET', len(HTTPMethod))  # → True 9
print(HTTPMethod.PATCH.description)  # → Apply partial modifications to a target.
try:
    HTTPMethod('get')
except ValueError as e:
    print(e)  # → 'get' is not a valid HTTPMethod
print(HTTPMethod('get'.upper()))  # → GET

See also

Open in the full glossarydocs.python.orgReport an inaccuracy