Skip to content

Commit 83356eb

Browse files
committed
check for 'content-encoding' to exist before accessing
1 parent 7eadff3 commit 83356eb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_requests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,10 @@ def text(self) -> str:
435435
return self._cached
436436
raise RuntimeError("Cannot access text after getting content or json")
437437

438-
if self.headers["content-encoding"] == "gzip":
438+
if (
439+
"content-encoding" in self.headers
440+
and self.headers["content-encoding"] == "gzip"
441+
):
439442
raise ValueError(
440443
"Content-encoding is gzip, data cannot be accessed as json or text. "
441444
"Use content property to access raw bytes."
@@ -456,7 +459,10 @@ def json(self) -> Any:
456459
if not self._raw:
457460
self._raw = _RawResponse(self)
458461

459-
if self.headers["content-encoding"] == "gzip":
462+
if (
463+
"content-encoding" in self.headers
464+
and self.headers["content-encoding"] == "gzip"
465+
):
460466
raise ValueError(
461467
"Content-encoding is gzip, data cannot be accessed as json or text. "
462468
"Use content property to access raw bytes."

0 commit comments

Comments
 (0)