12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import requests
- from typing import Dict, Any
- from common.setting import Config
- 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)
- # 处理响应
- 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)}")
|