简体   繁体   English

获取http状态代码

[英]Getting http status code

Is there any way to get http status in non-numeric way. 有没有办法以非数字方式获取http状态。 Like if I use http module I get http.HTTPStatus.ok which is numeric form of 200. However, I would like to get it as http.HTTPStatus.ok only in alphbetic way for comparision. 就像我使用http模块一样,我得到的是http.HTTPStatus.ok,它是200的数字形式。但是,我只想以字母的方式将其作为http.HTTPStatus.ok进行比较。

I am using a python code which executes an url and get the result back and result.response_code is http.HTTPStatus.ok. 我使用的是执行url并返回结果的python代码,resultse_code是http.HTTPStatus.ok。

Based on the documentation : 根据文档

>>> import http
>>> http.HTTPStatus.OK.phrase
'OK'

Based on what you've written you should therefore be able to do something like result.response_code.phrase . 因此,根据您所写的内容,您应该可以执行诸如result.response_code.phrase类的result.response_code.phrase If instead you get a number back you can reverse the lookup like this: 相反,如果您得到一个数字 ,则可以像这样反向查找:

>>> http.HTTPStatus(200).phrase
'OK'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM