Skip to content

Instantly share code, notes, and snippets.

@evanisnor
Created March 30, 2014 22:47
Show Gist options
  • Save evanisnor/9881258 to your computer and use it in GitHub Desktop.
Save evanisnor/9881258 to your computer and use it in GitHub Desktop.
HTTP Status Codes wrapped up in a Python 3 class
class HTTPStatusCode:
Continue = (100, 'Continue')
SwitchingProtocols = (101, 'Switching Protocols')
Checkpoint = (103, 'Checkpoint')
OK = (200, 'OK')
Created = (201, 'Created')
Accepted = (202, 'Accepted')
NonAuthoritativeInformation = (203, 'Non-Authoritative Information')
NoContent = (204, 'No Content')
ResetContent = (205, 'Reset Content')
PartialContent = (206, 'Partial Content')
MultipleChoices = (300, 'Multiple Choices')
MovedPermanently = (301, 'Moved Permanently')
Found = (302, 'Found')
SeeOther = (303, 'See Other')
NotModified = (304, 'Not Modified')
SwitchProxy = (306, 'Switch Proxy')
TemporaryRedirect = (307, 'Temporary Redirect')
ResumeIncomplete = (308, 'Resume Incomplete')
Unauthorized = (401, 'Unauthorized')
PaymentRequired = (402, 'Payment Required')
Forbidden = (403, 'Forbidden')
NotFound = (404, 'Not Found')
MethodNotAllowed = (405, 'Method Not Allowed')
NotAcceptable = (406, 'Not Acceptable')
ProxyAuthenticationRequired = (407, 'Proxy Authentication Required')
RequestTimeout = (408, 'Request Timeout')
Conflict = (409, 'Conflict')
Gone = (410, 'Gone')
LengthRequired = (411, 'Length Required')
PreconditionFailed = (412, 'Precondition Failed')
RequestEntityTooLarge = (413, 'Request Entity Too Large')
RequestURITooLong = (414, 'Request-URI Too Long')
UnsupportedMediaType = (415, 'Unsupported Media Type')
ExpectationFailed = (417, 'Expectation Failed')
NotImplemented = (501, 'Not Implemented')
BadGateway = (502, 'Bad Gateway')
ServiceUnavailable = (503, 'Service Unavailable')
GatewayTimeout = (504, 'Gateway Timeout')
HTTPVersionNotSupported = (505, 'HTTP Version Not Supported')
NetworkAuthenticationRequired = (511, 'Network Authentication Required')
@classmethod
def from_code(cls, code):
for attr in dir(cls):
if getattr(cls, attr)[0] == code:
return getattr(cls, attr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment