【问题标题】:Get status text after failed http-requesthttp-request 失败后获取状态文本
【发布时间】:2013-10-11 03:09:02
【问题描述】:

如果请求失败,是否有机会从我的 respose 对象中获取其他状态信息?此时,我可以获得状态码,但除此之外,我还需要状态信息文本(描述错误)。如果您使用的是 jQuery ajax,您可以从 jqXHR 的 responseText-attribute 获取此文本。

python-requests 响应是否有等价物?

rsp = requests.put(url='{0}recorditems/{1}'
                    .format(Utils.configuration['service']['baseURI']
                            , recorditemOID)
                    , data=body
                    , headers=headers
                    , cert=Utils.configuration['daemon']['certFile']
                    , verify=True)

if rsp.status_code == 200:
    Utils.log('Erfassung {0} synchronisiert'.format(recorditemOID))
    return True
else:
    Utils.log('Status-Code -> {0}'.format(rsp.status_code))

【问题讨论】:

    标签: python rest httprequest python-requests raspbian


    【解决方案1】:

    使用Response.reason 属性:

    r = requests.get('http://www.google.com/')
    print(r.reason)
    

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多