From b8e88becd58123524c1d397a782560f2bca777e3 Mon Sep 17 00:00:00 2001 From: q1139 <1139168548@qq.com> Date: Sat, 23 Dec 2023 11:33:49 +0800 Subject: [PATCH] fix: login user urlencode fix: get balance error log: add some log point --- login_tools.py | 3 ++- main/main.py | 3 +++ pandora_tools.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/login_tools.py b/login_tools.py index 154027d..d9cea44 100644 --- a/login_tools.py +++ b/login_tools.py @@ -2,6 +2,7 @@ import jwt from loguru import logger from flask import current_app +import urllib.parse def get_host(): @@ -13,7 +14,7 @@ def get_host(): # 使用用户名和密码登录 /api/auth/login def login(username, password): host = get_host() - payload = f'username={username}&password={password}' + payload = f'username={urllib.parse.quote(username)}&password={urllib.parse.quote(password)}' headers = { 'Content-Type': 'application/x-www-form-urlencoded' } diff --git a/main/main.py b/main/main.py index 66d0272..efdd5f9 100644 --- a/main/main.py +++ b/main/main.py @@ -108,6 +108,7 @@ def refresh(user_id): try: login_result = login_tools.login(user['email'], user['password']) except Exception as e: + logger.error(e) raise e access_token = login_result['access_token'] session_token = login_result['session_token'] @@ -116,6 +117,7 @@ def refresh(user_id): try: access_token_result = login_tools.get_access_token(user['session_token']) except Exception as e: + logger.error(e) raise e access_token = access_token_result['access_token'] session_token = access_token_result['session_token'] @@ -133,6 +135,7 @@ def refresh(user_id): share_token = share_tools.get_share_token(access_token, share['unique_name']) except Exception as e: # 返回刷新失败 + logger.error(e) raise e share['share_token'] = share_token['token_key'] # 更新share_list diff --git a/pandora_tools.py b/pandora_tools.py index 3716df8..6e3abe1 100644 --- a/pandora_tools.py +++ b/pandora_tools.py @@ -24,6 +24,8 @@ def fresh_setup(): @cached(cache=TTLCache(ttl=60, maxsize=1)) def get_balance(): response = requests.request("GET", f"https://dash.pandoranext.com/api/{current_app.config['license_id']}/usage") + if response.status_code != 200 or 'current' not in response.json(): + return {"current": 0,"total": "1"} return response.json()