migrate_issue/gitlink_api/login_api.py

37 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from requests import request
from loguru import logger
class Login:
"""登录"""
def __init__(self, host):
self.host = host
def login_api(self, user, pwd):
"""
登录接口
请求地址:{host}/api/accounts/login.json
请求方法POST
请求头:{"Content-Type": "application/json;charset=UTF-8"}
请求参数:
{
"login": {user}, # 用户名
"password": {pwd}, # 密码
"autologin": 1 # 前端是否勾选自动登录
}
"""
try:
headers = {"Content-Type": "application/json;charset=UTF-8"}
payload = {"login": user, "password": pwd,
"autologin": 1}
response = request(url=self.host + "/api/accounts/login.json", method="POST", headers=headers, json=payload)
json_data = response.json()
if json_data["login"] == user:
logger.debug(f'登录接口请求成功user_id={json_data["user_id"]} - login={json_data["login"]}')
return response
except Exception as e:
logger.error(f"登录接口请求错误:{e}")