Skip to content

Commit ea1c492

Browse files
authored
Merge pull request #100 from FoamyGuy/gzip_error
2 parents 9e28b6b + 83356eb commit ea1c492

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

adafruit_requests.py

+17
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ 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 (
439+
"content-encoding" in self.headers
440+
and self.headers["content-encoding"] == "gzip"
441+
):
442+
raise ValueError(
443+
"Content-encoding is gzip, data cannot be accessed as json or text. "
444+
"Use content property to access raw bytes."
445+
)
437446
self._cached = str(self.content, self.encoding)
438447
return self._cached
439448

@@ -450,6 +459,14 @@ def json(self) -> Any:
450459
if not self._raw:
451460
self._raw = _RawResponse(self)
452461

462+
if (
463+
"content-encoding" in self.headers
464+
and self.headers["content-encoding"] == "gzip"
465+
):
466+
raise ValueError(
467+
"Content-encoding is gzip, data cannot be accessed as json or text. "
468+
"Use content property to access raw bytes."
469+
)
453470
try:
454471
obj = json.load(self._raw)
455472
except OSError:

0 commit comments

Comments
 (0)