From 1379a2eca2800104a70f0ef19d39ba391c219b75 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 16 Feb 2023 11:22:41 +0100 Subject: [PATCH] Jira ServiceDesk: Fix create attachment (#1121) * Jira ServiceDesk: Fix create attachment In service_desk.py/attach_temporary_file a check was added to successfully post the request. * Corrected formatting with black of service_desk.py * undid wrong black formatting --------- Co-authored-by: Simon Kropf --- atlassian/service_desk.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/atlassian/service_desk.py b/atlassian/service_desk.py index cb0d0fcd9..328e1a6a9 100644 --- a/atlassian/service_desk.py +++ b/atlassian/service_desk.py @@ -523,11 +523,19 @@ def attach_temporary_file(self, service_desk_id, filename): experimental_headers["X-Atlassian-Token"] = "no-check" with open(filename, "rb") as file: - result = ( - self.post(path=url, headers=experimental_headers, files={"file": file}) - .json() - .get("temporaryAttachments") - ) + # bug https://github.com/atlassian-api/atlassian-python-api/issues/1056 + # in advanced_mode it returns the raw response therefore .json() is needed + # in normal mode this is not needed and would fail + if self.advanced_mode: + result = ( + self.post(path=url, headers=experimental_headers, files={"file": file}) + .json() + .get("temporaryAttachments") + ) + else: + result = self.post(path=url, headers=experimental_headers, files={"file": file}).get( + "temporaryAttachments" + ) temp_attachment_id = result[0].get("temporaryAttachmentId") return temp_attachment_id