Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ def text(self) -> str:
if isinstance(self._cached, str):
return self._cached
raise RuntimeError("Cannot access text after getting content or json")

if (
"content-encoding" in self.headers
and self.headers["content-encoding"] == "gzip"
):
raise ValueError(
"Content-encoding is gzip, data cannot be accessed as json or text. "
"Use content property to access raw bytes."
)
self._cached = str(self.content, self.encoding)
return self._cached

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

if (
"content-encoding" in self.headers
and self.headers["content-encoding"] == "gzip"
):
raise ValueError(
"Content-encoding is gzip, data cannot be accessed as json or text. "
"Use content property to access raw bytes."
)
try:
obj = json.load(self._raw)
except OSError:
Expand Down