From cd7e154ecbf076e7d33032180173bede8d6cd559 Mon Sep 17 00:00:00 2001 From: Michael Lavrisha <36475+vrish88@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:00:37 -0600 Subject: [PATCH] Prevent error from being raised when content type header is missing --- smartsheet/smartsheet.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smartsheet/smartsheet.py b/smartsheet/smartsheet.py index fab6a63..fa5a27d 100644 --- a/smartsheet/smartsheet.py +++ b/smartsheet/smartsheet.py @@ -279,16 +279,16 @@ def _log_request(self, operation, response): response.request.url, ) if response.request.body is not None: - body_dumps = f'"<< {response.request.headers["Content-Type"]} content type suppressed >>"' + body_dumps = f'"<< {response.request.headers.get("Content-Type")} content type suppressed >>"' if is_multipart(response.request): body_dumps = '"<< multipart body suppressed >>"' - elif "application/json" in response.request.headers["Content-Type"]: + elif "application/json" in response.request.headers.get("Content-Type"): body = response.request.body.decode("utf8") body_dumps = json.dumps(json.loads(body), sort_keys=True) self._log.debug('{"requestBody": %s}', body_dumps) # response - content_dumps = f'"<< {response.headers["Content-Type"]} content type suppressed >>"' - if "application/json" in response.headers["Content-Type"]: + content_dumps = f'"<< {response.headers.get("Content-Type")} content type suppressed >>"' + if "application/json" in response.headers.get("Content-Type"): content = response.content.decode("utf8") content_dumps = json.dumps(json.loads(content), sort_keys=True) if 200 <= response.status_code <= 299: