fix(weibo): 识别支付域登录失效

This commit is contained in:
yml2213
2026-11-08 14:06:26 +08:00
parent ed15701392
commit 7f7a8f6004
4 changed files with 86 additions and 3 deletions
+12 -2
View File
@@ -15,6 +15,7 @@ import json
import secrets
import time
from dataclasses import dataclass
from html import unescape
from html.parser import HTMLParser
from typing import Any
from urllib.parse import parse_qs, urljoin, urlsplit
@@ -321,6 +322,7 @@ class WeiboClient:
data: dict[str, Any] | None = None,
json: dict[str, Any] | None = None,
) -> dict[str, Any]:
response: requests.Response | None = None
try:
response = self.session.request(
method,
@@ -333,10 +335,18 @@ class WeiboClient:
)
response.raise_for_status()
payload = response.json()
except (requests.exceptions.JSONDecodeError, ValueError) as exc:
text = unescape(response.text if response is not None else "")
if "retcode=6102" in text or "/sso/login.php" in text:
raise WeiboAuthError(
"微博支付/活动域登录态已失效(retcode=6102),"
"请重新登录微博后重新导入 CK"
) from exc
path = urlsplit(response.url).path if response is not None else ""
suffix = f": {path}" if path else ""
raise WeiboTransportError(f"微博接口返回非 JSON{suffix}") from exc
except requests.RequestException as exc:
raise WeiboTransportError(f"请求微博失败: {exc}") from exc
except ValueError as exc:
raise WeiboTransportError("微博返回内容不是合法 JSON") from exc
if not isinstance(payload, dict):
raise WeiboTransportError("微博返回 JSON 结构异常")
return payload