From fd47f0aa2ab42ce4690155a0069efbc9ce3aef3a Mon Sep 17 00:00:00 2001 From: Aniko Bartos Date: Tue, 12 Dec 2023 13:20:58 +0100 Subject: [PATCH] Fixed missing header in check, add error handling --- sandboxapi/opswat.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sandboxapi/opswat.py b/sandboxapi/opswat.py index 276b5d2..e6fa7ac 100644 --- a/sandboxapi/opswat.py +++ b/sandboxapi/opswat.py @@ -83,7 +83,9 @@ def check(self, item_id): :rtype: bool :return: Boolean indicating if a report is done or not. """ - response = self._request("/api/scan/{flow_id}/report".format(flow_id=item_id)) + response = self._request( + "/api/scan/{flow_id}/report".format(flow_id=item_id), headers=self.headers + ) if response.status_code == 404: # unknown id @@ -92,6 +94,11 @@ def check(self, item_id): try: if "allFinished" in response.json() and response.json()["allFinished"]: return True + elif "allFinished" not in response.json(): + raise sandboxapi.SandboxError( + "api error in check ({u}): {r}".format( + u=response.url, r=response.content + )) except ValueError as e: raise sandboxapi.SandboxError(e) @@ -151,7 +158,7 @@ def report(self, item_id, report_format="json"): "filter=taskReference", "filter=subtaskReferences", "filter=allSignalGroups", - "filter=iocs" + "filter=iocs", ] postfix = "&".join(filters)