Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add fallback for orjson #170

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions utils/api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from os import getenv
from typing import Dict, List, Optional, Union

import orjson
try:
import orjson as json
except:
import json

from ..config import Account, write_plugin_data
from ..data_model import LoginResultHandler
Expand Down Expand Up @@ -72,7 +75,7 @@ async def login(self) -> Union[Dict[str, str], bool]:
response = await post('https://account.xiaomi.com/pass/serviceLoginAuth2', headers=headers, data=data)
log.debug(response.text)
result = response.text.lstrip('&').lstrip('START').lstrip('&')
data = orjson.loads(result)
data = json.loads(result)
api_data = LoginResultHandler(data)
if api_data.success:
log.success('小米账号登录成功')
Expand Down
8 changes: 6 additions & 2 deletions utils/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import os
from hashlib import md5
from pathlib import Path
from typing import Dict, List, Optional, Union
from hashlib import md5

import yaml
from loguru import logger as log
from orjson import JSONDecodeError
from pydantic import BaseModel, ValidationError, validator

try:
from orjson import JSONDecodeError
except:
from json import JSONDecodeError

ROOT_PATH = Path(__name__).parent.absolute()

DATA_PATH = ROOT_PATH / "data"
Expand Down