在Python请求中获取状态代码的描述

编程入门 行业动态 更新时间:2024-10-26 03:35:19
本文介绍了在Python请求中获取状态代码的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望能够输入服务器响应代码并让请求告诉我代码的含义。例如,代码200 - >确定

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

我找到了源代码,显示代码和描述的字典结构。我看到Requests将返回给定描述的响应代码:

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

但不是相反:

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.

推荐答案

一种可能性:

>>> 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.

更多推荐

在Python请求中获取状态代码的描述

本文发布于:2023-11-15 19:02:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1597138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   代码   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!