From 602e6091156341944f2f4988718ec34d44780bf5 Mon Sep 17 00:00:00 2001 From: Akiqqqqqqq <745869055@qq.com> Date: Tue, 14 Nov 2023 21:11:18 +0800 Subject: [PATCH] fix null key --- media_platform/xhs/client.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/media_platform/xhs/client.py b/media_platform/xhs/client.py index 0064359..69cc2d6 100644 --- a/media_platform/xhs/client.py +++ b/media_platform/xhs/client.py @@ -186,6 +186,13 @@ class XHSClient: comments_res = await self.get_note_comments(note_id, comments_cursor) comments_has_more = comments_res.get("has_more", False) comments_cursor = comments_res.get("cursor", "") + # Check if 'comments' key exists in the response + if "comments" not in comments_res: + # Handle the absence of 'comments' key appropriately + # For example, log an error message, break from the loop, etc. + # This is just an example: + print(f"No 'comments' key found in response: {comments_res}") + break comments = comments_res["comments"] if not is_fetch_sub_comments: result.extend(comments)