src/requests/status_codes.pypython
139 baris ditampilkan
2
The ``codes`` object defines a mapping from common names for HTTP statuses
3
to their numerical codes, accessible either as attributes or as dictionary
9
>>> requests.codes['temporary_redirect']
11
>>> requests.codes.teapot
13
>>> requests.codes['\o/']
16
Some codes have multiple names, and both upper- and lower-case versions of
17
the names are allowed. For example, ``codes.ok``, ``codes.OK``, and
18
``codes.okay`` all correspond to the HTTP status code 200.
21
from .structures import LookupDict
26
101: ("switching_protocols",),
27
102: ("processing", "early-hints"),
29
122: ("uri_too_long", "request_uri_too_long"),
30
200: ("ok", "okay", "all_ok", "all_okay", "all_good", "\\o/", "✓"),
33
203: ("non_authoritative_info", "non_authoritative_information"),
35
205: ("reset_content", "reset"),
36
206: ("partial_content", "partial"),
37
207: ("multi_status", "multiple_status", "multi_stati", "multiple_stati"),
38
208: ("already_reported",),
41
300: ("multiple_choices",),
42
301: ("moved_permanently", "moved", "\\o-"),
44
303: ("see_other", "other"),
45
304: ("not_modified",),
47
306: ("switch_proxy",),
48
307: ("temporary_redirect", "temporary_moved", "temporary"),
53
), # "resume" and "resume_incomplete" to be removed in 3.0
55
400: ("bad_request", "bad"),
56
401: ("unauthorized",),
57
402: ("payment_required", "payment"),
59
404: ("not_found", "-o-"),
60
405: ("method_not_allowed", "not_allowed"),
61
406: ("not_acceptable",),
62
407: ("proxy_authentication_required", "proxy_auth", "proxy_authentication"),
63
408: ("request_timeout", "timeout"),
66
411: ("length_required",),
67
412: ("precondition_failed", "precondition"),
68
413: ("request_entity_too_large", "content_too_large"),
69
414: ("request_uri_too_large", "uri_too_long"),
70
415: ("unsupported_media_type", "unsupported_media", "media_type"),
72
"requested_range_not_satisfiable",
74
"range_not_satisfiable",
76
417: ("expectation_failed",),
77
418: ("im_a_teapot", "teapot", "i_am_a_teapot"),
72
"requested_range_not_satisfiable",
74
"range_not_satisfiable",
76
417: ("expectation_failed",),
77
418: ("im_a_teapot", "teapot", "i_am_a_teapot"),
78
421: ("misdirected_request",),
79
422: ("unprocessable_entity", "unprocessable", "unprocessable_content"),
81
424: ("failed_dependency", "dependency"),
82
425: ("unordered_collection", "unordered", "too_early"),
83
426: ("upgrade_required", "upgrade"),
84
428: ("precondition_required", "precondition"),
85
429: ("too_many_requests", "too_many"),
86
431: ("header_fields_too_large", "fields_too_large"),
87
444: ("no_response", "none"),
88
449: ("retry_with", "retry"),
89
450: ("blocked_by_windows_parental_controls", "parental_controls"),
90
451: ("unavailable_for_legal_reasons", "legal_reasons"),
91
499: ("client_closed_request",),
93
500: ("internal_server_error", "server_error", "/o\\", "✗"),
94
501: ("not_implemented",),
95
502: ("bad_gateway",),
96
503: ("service_unavailable", "unavailable"),
97
504: ("gateway_timeout",),
98
505: ("http_version_not_supported", "http_version"),
99
506: ("variant_also_negotiates",),
100
507: ("insufficient_storage",),
101
509: ("bandwidth_limit_exceeded", "bandwidth"),
102
510: ("not_extended",),
103
511: ("network_authentication_required", "network_auth", "network_authentication"),
106
codes: LookupDict[int] = LookupDict(name="status_codes")
102
510: ("not_extended",),
103
511: ("network_authentication_required", "network_auth", "network_authentication"),
106
codes: LookupDict[int] = LookupDict(name="status_codes")
110
for code, titles in _codes.items():
112
setattr(codes, title, code)
113
if not title.startswith(("\\", "/")):
114
setattr(codes, title.upper(), code)
116
def doc(code: int) -> str:
117
names = ", ".join(f"``{n}``" for n in _codes[code])
118
return "* %d: %s" % (code, names)
122
__doc__ + "\n" + "\n".join(doc(code) for code in sorted(_codes))
123
if __doc__ is not None