From 152c4d4b918b0c6c616ab5d4bae3ab5d905b5fe3 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 3 Jun 2024 18:28:22 +0530 Subject: [PATCH] fix(make_request): don't blindly try to check the content-type Ensure that the response has one first Signed-off-by: Akhil Narang --- frappe/integrations/utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frappe/integrations/utils.py b/frappe/integrations/utils.py index 09907ba784..bb4f62463b 100644 --- a/frappe/integrations/utils.py +++ b/frappe/integrations/utils.py @@ -21,15 +21,15 @@ def make_request(method: str, url: str, auth=None, headers=None, data=None, json ) response.raise_for_status() - content_type = response.headers.get("content-type") - if content_type == "text/plain; charset=utf-8": - return parse_qs(response.text) - elif content_type.startswith("application/") and content_type.split(";")[0].endswith("json"): - return response.json() - elif response.text: - return response.text - else: - return + # Check whether the response has a content-type, before trying to check what it is + if content_type := response.headers.get("content-type"): + if content_type == "text/plain; charset=utf-8": + return parse_qs(response.text) + elif content_type.startswith("application/") and content_type.split(";")[0].endswith("json"): + return response.json() + elif response.text: + return response.text + return except Exception as exc: if frappe.flags.integration_request_doc: frappe.flags.integration_request_doc.log_error()