1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import requests
- from typing import Dict, Any
- from sympy.polys.polyconfig import configure
- from common import config
- from common.utils import call_api
- class LoginApi:
- def __init__(self):
- self.token = None
- def login_bmc(self, username: str, password: str, client: str = "RIIL") -> Dict[str, Any]:
- """
- 登录BMC接口方法。
- :param base_url: API的基地址,例如"http://example.com"
- :param username: 用户名
- :param password: 密码
- :param client: 调用接口的客户端,默认为"RIIL"
- :return: 包含响应数据的字典
- :raises: 请求错误或响应异常
- """
- url = f'{config.BASE_URL}/login'
- # 构造请求参数
- params = {
- "username": username,
- "password": password,
- "_openCLIENT": client
- }
- try:
- # 发送GET请求
- response = requests.get(url, params=params, verify=False)
- # 处理响应
- if response.status_code == 200:
- return {
- "success": True,
- "data": response.json(),
- "cookies": response.cookies.get_dict()
- }
- return {
- "success": False,
- "data": response.json(),
- "cookies": None
- }
- except requests.RequestException as e:
- raise RuntimeError(f"请求失败: {str(e)}")
|