File tree 1 file changed +17
-0
lines changed
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:
434
434
if isinstance (self ._cached , str ):
435
435
return self ._cached
436
436
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
+ )
437
446
self ._cached = str (self .content , self .encoding )
438
447
return self ._cached
439
448
@@ -450,6 +459,14 @@ def json(self) -> Any:
450
459
if not self ._raw :
451
460
self ._raw = _RawResponse (self )
452
461
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
+ )
453
470
try :
454
471
obj = json .load (self ._raw )
455
472
except OSError :
You can’t perform that action at this time.
0 commit comments