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