1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python获取状态码_Python 如何获取接口返回的http状态码

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

时间:2018-07-07 07:46:18

相关推荐

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

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

示例代码:

import requests

import json

url = '/loginAccount'

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

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

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

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

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

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

#print(res.headers) # 响应头

url2 = '/show?t=1571107362548&token=3c55b539bd8d0a31f7f673ad6334235daa9c2cf5'

res2 = requests.get(url2)

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

返回结果:

返回结果

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。