From d46475ca8c037b24f3f7d5ec34fc1cb657675f45 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:39:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(maizone):=20=E5=A2=9E=E5=BC=BA=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=A9=BA=E9=97=B4=E5=8A=A8=E6=80=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E5=81=A5=E5=A3=AE=E6=80=A7=E4=BB=A5=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QQ空间API在某些情况下可能返回非预期的数据格式,例如 `pictotal` 或 `commentlist` 字段为 `None` 而不是空列表。 之前的代码直接对这些字段进行迭代,当遇到非列表类型时会导致 `TypeError` 异常,从而中断动态的获取流程。 本次修改通过在处理图片和评论列表前添加 `isinstance` 类型检查,确保了只在数据结构符合预期时才进行操作,从而避免了因API返回数据格式异常而导致的程序崩溃。 --- .../services/qzone_service.py | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/plugins/built_in/maizone_refactored/services/qzone_service.py b/src/plugins/built_in/maizone_refactored/services/qzone_service.py index 40c0d424a..2022461f7 100644 --- a/src/plugins/built_in/maizone_refactored/services/qzone_service.py +++ b/src/plugins/built_in/maizone_refactored/services/qzone_service.py @@ -740,28 +740,42 @@ class QZoneService: feeds_list = [] my_name = json_data.get("logininfo", {}).get("name", "") for msg in json_data.get("msglist", []): + # 只有在处理好友说说时,才检查是否已评论并跳过 + commentlist = msg.get("commentlist") + # 只有在处理好友说说时,才检查是否已评论并跳过 if not is_monitoring_own_feeds: - is_commented = any( - c.get("name") == my_name for c in msg.get("commentlist", []) if isinstance(c, dict) - ) + is_commented = False + if isinstance(commentlist, list): + is_commented = any( + c.get("name") == my_name for c in commentlist if isinstance(c, dict) + ) if is_commented: continue - images = [pic["url1"] for pic in msg.get("pictotal", []) if "url1" in pic] + # --- 安全地处理图片列表 --- + images = [] + pictotal = msg.get("pictotal") + if isinstance(pictotal, list): + images = [ + pic["url1"] for pic in pictotal if isinstance(pic, dict) and "url1" in pic + ] + # --- 安全地处理评论列表 --- comments = [] - if "commentlist" in msg: - for c in msg["commentlist"]: - comments.append( - { - "qq_account": c.get("uin"), - "nickname": c.get("name"), - "content": c.get("content"), - "comment_tid": c.get("tid"), - "parent_tid": c.get("parent_tid"), # API直接返回了父ID - } - ) + if isinstance(commentlist, list): + for c in commentlist: + # 确保评论条目也是字典 + if isinstance(c, dict): + comments.append( + { + "qq_account": c.get("uin"), + "nickname": c.get("name"), + "content": c.get("content"), + "comment_tid": c.get("tid"), + "parent_tid": c.get("parent_tid"), + } + ) feeds_list.append( {