Merge pull request #26656 from akhilnarang/request-check-content-type

fix(make_request): don't blindly try to check the content-type
This commit is contained in:
Akhil Narang 2024-06-04 10:59:39 +05:30 committed by GitHub
commit fb2df4ab5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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()