From 228b5017c1eabfc88ea63bd2852f371048f1c75a Mon Sep 17 00:00:00 2001 From: Bao-qing <919836565@qq.com> Date: Sun, 5 Jul 2026 23:40:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20API=5FBASE=5FURL=20?= =?UTF-8?q?=E5=92=8C=20SITE=5FBASE=5FURL=20=E7=9A=84=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BA=20JSON=20=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pan123_core.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pan123_core.py b/pan123_core.py index 4e619db..dd5ca19 100644 --- a/pan123_core.py +++ b/pan123_core.py @@ -25,11 +25,14 @@ import requests # ════════════════════════════════════════════════════════════════ # ── 基础域名 ────────────────────────────────────────────────── -API_BASE_URL = "https://www.123pan.com" +SITE_BASE_URL = "https://www.123pan.com" +"""123pan 网站根地址""" + +API_BASE_URL = "https://api.123278.com" """123pan API 根地址""" # ── 接口端点(相对路径,使用时拼接 API_BASE_URL)──────────────── -URL_LOGIN = "/b/api/user/sign_in" +URL_LOGIN = "/api/user/sign_in" """登录接口""" URL_FILE_LIST = "/api/file/list/new" @@ -69,7 +72,7 @@ URL_DETAILS = "/b/api/restful/goapi/v1/file/details" """获取文件夹详情接口""" SHARE_URL_TEMPLATE = "{base}/s/{key}" -"""分享链接模板,{base} = API_BASE_URL,{key} = ShareKey""" +"""分享链接模板,{base} = SITE_BASE_URL,{key} = ShareKey""" # ── 超时配置(秒)──────────────────────────────────────────── TIMEOUT_DEFAULT = 15 @@ -478,7 +481,19 @@ class Pan123Core: params=params, timeout=timeout, ) - data = resp.json() + try: + data = resp.json() + except ValueError: + content_type = resp.headers.get("content-type", "unknown") + preview = (resp.text or "").strip().replace("\r", " ").replace("\n", " ") + if len(preview) > 200: + preview = f"{preview[:200]}..." + if not preview: + preview = "" + return make_result( + -2, + f"响应 JSON 解析错误: HTTP {resp.status_code}, Content-Type: {content_type}, Body: {preview}", + ) api_code = data.get("code", -1) # 123pan 登录成功/退出登录 成功返回 code 200,其余接口成功返回 0 if api_code not in (CODE_OK, CODE_LOGIN_OK): @@ -486,8 +501,6 @@ class Pan123Core: return make_result(CODE_OK, "ok", data) except requests.RequestException as e: return make_result(-1, f"请求失败: {e}") - except json.JSONDecodeError: - return make_result(-2, "响应 JSON 解析错误") # ════════════════════════════════════════════════════════════ # 用户信息 @@ -996,7 +1009,7 @@ class Pan123Core: if r["code"] != CODE_OK: return r key = r["data"]["data"]["ShareKey"] - share_url = SHARE_URL_TEMPLATE.format(base=API_BASE_URL, key=key) + share_url = SHARE_URL_TEMPLATE.format(base=SITE_BASE_URL, key=key) return make_result(CODE_OK, "分享创建成功", { "share_url": share_url, "share_pwd": share_pwd,