File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments