From f007c1c772788326dd4f10b5eec73c51c1ec965e Mon Sep 17 00:00:00 2001 From: Liu An Date: Thu, 5 Jun 2025 18:03:51 +0800 Subject: [PATCH] Fix: Resolve JSON download errors in Document.download() (#8084) ### What problem does this PR solve? An exception is thrown only when the json file has only two keys, `code` and `message`. In other cases, response.content is returned normally. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- sdk/python/ragflow_sdk/modules/document.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/python/ragflow_sdk/modules/document.py b/sdk/python/ragflow_sdk/modules/document.py index 240138aa9..6cb0e3b5e 100644 --- a/sdk/python/ragflow_sdk/modules/document.py +++ b/sdk/python/ragflow_sdk/modules/document.py @@ -63,9 +63,14 @@ class Document(Base): def download(self): res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}") + error_keys = set(["code", "message"]) try: - res = res.json() - raise Exception(res.get("message")) + response = res.json() + actual_keys = set(response.keys()) + if actual_keys == error_keys: + raise Exception(res.get("message")) + else: + return res.content except json.JSONDecodeError: return res.content