python获取状态码_Python 如何获取接口返回的http状态码

使用request 模块得到返回值,然后再利用status_code属性获取http响应的状态码。

示例代码:

import requests

import json

url = 'http://dev.xxx.com/loginAccount'

data = {"account": "companyG", "adminUserCode": "000009", "companyCode": "53c3aeab8c1e11e9898400163e138319", "password": "c4ca4238a0b923820dcc509a6f75849b", "timestamp": "20191009112205", "sign": "55efce47806e2056adfa0cb769c274c8"}

header = {"Content-Type":"application/json"}

res = requests.post(url,json=data,headers=header) #这里的语法参见 https://blog.csdn.net/weixin_43709411/article/details/91046552

# 3.解析响应:输出响应文本等等

#print(res.text) # 输出响应的文本

print("接口1状态:",res.status_code) # 状态码

#print(res.headers) # 响应头

url2 = 'https://dev.xxx.com/show?t=1571107362548&token=3c55b539bd8d0a31f7f673ad6334235daa9c2cf5'

res2 = requests.get(url2)

print("接口2状态:",res2.status_code)

返回结果:

返回结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值