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']