Skip to content

Commit

Permalink
fix: login user urlencode
Browse files Browse the repository at this point in the history
fix: get balance error
log: add some log point
  • Loading branch information
nianhua99 committed Dec 23, 2023
1 parent f1c9881 commit b8e88be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion login_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import jwt
from loguru import logger
from flask import current_app
import urllib.parse


def get_host():
Expand All @@ -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'
}
Expand Down
3 changes: 3 additions & 0 deletions main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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']
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pandora_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit b8e88be

Please sign in to comment.