++
This commit is contained in:
@@ -1 +0,0 @@
|
||||
['jack0210_@hotmail.com', '!QAZ2wsx+0913']
|
||||
+14
-15
@@ -1,20 +1,20 @@
|
||||
import httpx
|
||||
from httpx import BasicAuth
|
||||
import os
|
||||
|
||||
|
||||
def login(credentials_file='account.txt'):
|
||||
"""登录WorldQuant Brain API"""
|
||||
# 读取本地账号密码
|
||||
if not os.path.exists(credentials_file):
|
||||
print("未找到 account.txt 文件")
|
||||
with open(credentials_file, 'w') as f: f.write("")
|
||||
print("account.txt 文件已创建,请填写账号密码, 格式: ['username', 'password]")
|
||||
exit(1)
|
||||
# 从nacos获取账号密码
|
||||
nacos_resp = httpx.get('http://192.168.31.41:30848/nacos/v1/cs/configs?dataId=wq_account&group=quantify')
|
||||
if nacos_resp.status_code != 200:
|
||||
print('获取账号密码失败')
|
||||
return False
|
||||
|
||||
config = nacos_resp.json()
|
||||
|
||||
username = config['user_name']
|
||||
password = config['password']
|
||||
|
||||
with open(credentials_file) as f:
|
||||
credentials = eval(f.read())
|
||||
username, password = credentials[0], credentials[1]
|
||||
|
||||
print(f"正在登录账户: {username}")
|
||||
|
||||
# 创建客户端并认证
|
||||
@@ -34,7 +34,6 @@ def login(credentials_file='account.txt'):
|
||||
return None
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
client = login()
|
||||
if client:
|
||||
client.close()
|
||||
client = login()
|
||||
if client:
|
||||
client.close()
|
||||
Reference in New Issue
Block a user