Skip to content

Commit 7eadff3

Browse files
committed
raise error indicating gzipped data
1 parent 9e28b6b commit 7eadff3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

adafruit_requests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ def text(self) -> str:
434434
if isinstance(self._cached, str):
435435
return self._cached
436436
raise RuntimeError("Cannot access text after getting content or json")
437+
438+
if self.headers["content-encoding"] == "gzip":
439+
raise ValueError(
440+
"Content-encoding is gzip, data cannot be accessed as json or text. "
441+
"Use content property to access raw bytes."
442+
)
437443
self._cached = str(self.content, self.encoding)
438444
return self._cached
439445

@@ -450,6 +456,11 @@ def json(self) -> Any:
450456
if not self._raw:
451457
self._raw = _RawResponse(self)
452458

459+
if self.headers["content-encoding"] == "gzip":
460+
raise ValueError(
461+
"Content-encoding is gzip, data cannot be accessed as json or text. "
462+
"Use content property to access raw bytes."
463+
)
453464
try:
454465
obj = json.load(self._raw)
455466
except OSError:

0 commit comments

Comments
 (0)