Python接口测试中通过登录接口获取实时token

1、封装login_token

2、headers:对应登录请求头部信息

3、request_param:登录的参数数据

4、json.dumps:将一个Python数据结构转换为JSON

5、dict(response.json()):获取的json转换成dict格式

6、return dict_token['data']['token']:返回对应的token数据

7、供后面模块调用login_token,方便参数化

from Business.url import url
import requests, json def login_token(username, password):
'''获取登录后的token''' headers = {'Content-Type': 'application/json;charset=UTF-8'} request_param = {
"username": username,
"password": password
}
response = requests.post(url, data=json.dumps(request_param), headers=headers) # 返回JSON中data数据的token
return response.json()['data']['token']

提供一个思路

python+excel接口自动化获取token并将token作为参数传给下个接口:https://blog.csdn.net/weixin_42760923/article/details/100122235

上一篇:python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告


下一篇:Go-directed and habitual learning