handle_token.py
996 Bytes
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2022/12/15 22:55
# @Author : Shitou
# @FileName: handle_token.py
# @Software: PyCharm
"""
登陆获取token
"""
import requests
from common.handle_config import conf
from jsonpath import jsonpath
class LoginToken:
def login_token():
# 登陆获取token
login_url = conf.get("url", "url_ip") + "/auth/v1/login"
headers = eval(conf.get('url', 'login_token'))
params = {
"way": conf.get('user_data', 'way'),
"password": conf.get('user_data', 'userpassword'),
"type": conf.get('user_data', 'type'),
"username": conf.get('user_data', 'username'),
}
response = requests.request(url=login_url, method="post", json=params, headers=headers)
res = response.json()
# 获取token
token = "Bearer" + " " + jsonpath(res, "$..access_token")[0]
return token
if __name__ == '__main__':
LoginToken.login_token()