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)
This commit is contained in:
Liu An
2025-06-05 18:03:51 +08:00
committed by GitHub
parent 841291dda0
commit f007c1c772

View File

@ -63,9 +63,14 @@ class Document(Base):
def download(self): def download(self):
res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}") res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}")
error_keys = set(["code", "message"])
try: try:
res = res.json() response = res.json()
raise Exception(res.get("message")) actual_keys = set(response.keys())
if actual_keys == error_keys:
raise Exception(res.get("message"))
else:
return res.content
except json.JSONDecodeError: except json.JSONDecodeError:
return res.content return res.content