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.
This commit is contained in:
myd7349
2024-06-18 00:00:34 +08:00
parent 7d8a3abd5c
commit 2ddeb144b9

View File

@@ -334,7 +334,11 @@ class Kindle:
if not result.get("success", True):
logger.error("get all books error: %s", result.get("error"))
break
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"])