获取 Python Requests 中状态码的描述 [英] Get the description of a status code in Python Requests
问题描述
我希望能够输入服务器响应代码并让请求告诉我代码的含义.例如,代码 200 --> ok
我找到了一个指向 源代码的链接,它显示代码和描述的字典结构.我看到请求将返回给定描述的响应代码:
print requests.codes.processing # 返回 102打印 requests.codes.ok # 返回 200打印 requests.codes.not_found # 返回 404
反之亦然:
print requests.codes[200] # 返回无打印 requests.codes.viewkeys() # 返回 dict_keys([])打印 requests.codes.keys() # 返回 []
我认为这将是一项例行任务,但似乎无法在在线搜索或 文档.
一种可能性:
<预><代码>>>>进口请求>>>requests.status_codes._codes[200]('ok', 'ok', 'all_ok', 'all_okay', 'all_good', '\o/', 'xe2x9cx93')元组中的第一个值用作常规代码键.
I would like to be able to enter a server response code and have Requests tell me what the code means. For example, code 200 --> ok
I found a link to the source code which shows the dictionary structure of the codes and descriptions. I see that Requests will return a response code for a given description:
print requests.codes.processing # returns 102
print requests.codes.ok # returns 200
print requests.codes.not_found # returns 404
But not the other way around:
print requests.codes[200] # returns None
print requests.codes.viewkeys() # returns dict_keys([])
print requests.codes.keys() # returns []
I thought this would be a routine task, but cannot seem to find an answer to this in online searching, or in the documentation.
One possibility:
>>> import requests
>>> requests.status_codes._codes[200]
('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\o/', 'xe2x9cx93')
The first value in the tuple is used as the conventional code key.
这篇关于获取 Python Requests 中状态码的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!