一、封裝login_tokenjson
二、headers
:對應登陸請求頭部信息數據結構
三、request_param
:登陸的參數數據app
四、json.dumps
:將一個Python數據結構轉換爲JSONpost
五、dict(response.json())
:獲取的json轉換成dict格式url
六、return dict_token['data']['token']
:返回對應的token數據code
七、供後面模塊調用login_token,方便參數化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']