From 2ddeb144b99e55b422204f4bc023a31e26da9c5e Mon Sep 17 00:00:00 2001 From: myd7349 Date: Tue, 18 Jun 2024 00:00:34 +0800 Subject: [PATCH] fix: handle potential KeyError When fetching a large number of personal documents, there is a chance of receiving the following JSON structure leading to a KeyError: ```json {"OwnershipData":{"success":false,"error":"GENERIC_ERROR"}} ``` In this case, ignore the error and continue execution. --- kindle_download_helper/kindle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kindle_download_helper/kindle.py b/kindle_download_helper/kindle.py index b65e51a..14d7924 100644 --- a/kindle_download_helper/kindle.py +++ b/kindle_download_helper/kindle.py @@ -334,7 +334,11 @@ class Kindle: if not result.get("success", True): logger.error("get all books error: %s", result.get("error")) break - items = result["OwnershipData"]["items"] + try: + items = result["OwnershipData"]["items"] + except KeyError: + logger.error("get all books error: %s", result.get("error")) + break for item in items: if filetype == "PDOC": item["title"] = html.unescape(item["title"])