Get the description of a status code in Python Requests

One possibility:

>>> import requests
>>> requests.status_codes._codes[200]
('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '\xe2\x9c\x93')

The first value in the tuple is used as the conventional code key.


Alternatively, in case of Python 2.x, you can use httplib.responses:

>>> import httplib
>>> httplib.responses[200]
'OK'
>>> httplib.responses[404]
'Not Found'

In Python 3.x, use http module:

In [1]: from http.client import responses

In [2]: responses[200]
Out[2]: 'OK'

In [3]: responses[404]
Out[3]: 'Not Found'