fix: 即席查询从登记过的入口续票据,有效必须能进入查询
This commit is contained in:
@@ -15,6 +15,7 @@ from app.nqi.constants import ORIGIN
|
||||
|
||||
ADHOC = f"{ORIGIN}/pro-adhoc"
|
||||
PAGE = f"{ADHOC}/adhocquery"
|
||||
ENTRY = f"{ADHOC}/index"
|
||||
PAGE_SIZE = 200
|
||||
MAX_PAGES = 2000
|
||||
TIME_MODES = {"prev_month", "prev_week", "prev_day", "prev_weeks", "prev_months", "prev_days"}
|
||||
@@ -55,14 +56,18 @@ def _end(day: date) -> datetime:
|
||||
|
||||
|
||||
async def ensure_session(client: NqiClient) -> None:
|
||||
"""门户凭证有效时,还要先打开即席查询,才会拿到这个应用自己的会话。"""
|
||||
"""单点入口是 /pro-adhoc/index。票据有效时,这里会换成即席查询自己的会话。"""
|
||||
response = await client._request(
|
||||
"GET",
|
||||
PAGE,
|
||||
headers={"Referer": f"{ORIGIN}/pro-portal/"},
|
||||
ENTRY,
|
||||
headers={
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Referer": f"{ORIGIN}/pro-portal/",
|
||||
"Upgrade-Insecure-Requests": "1",
|
||||
},
|
||||
check_auth=False,
|
||||
)
|
||||
if _landed_on_login(response):
|
||||
if response.status_code >= 400 or _landed_on_login(response):
|
||||
raise NqiAuthError("登录已失效,请重新登录")
|
||||
|
||||
|
||||
|
||||
@@ -164,6 +164,10 @@ class NqiClient:
|
||||
)
|
||||
return exported
|
||||
|
||||
def replace_cookies(self, cookies: list[dict]) -> None:
|
||||
self.client.cookies.clear()
|
||||
self.import_cookies(cookies)
|
||||
|
||||
def import_cookies(self, cookies: list[dict]) -> None:
|
||||
for cookie in cookies:
|
||||
if not cookie.get("name"):
|
||||
@@ -319,9 +323,11 @@ class NqiClient:
|
||||
"""用单点票据进入即席查询。票据还有效时,这一步会把它续上。"""
|
||||
from app.nqi.adhoc import ensure_session
|
||||
|
||||
saved = self.export_cookies()
|
||||
try:
|
||||
await ensure_session(self)
|
||||
except NqiAuthError:
|
||||
self.replace_cookies(saved)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user