fix: Add .text property to HttpResponse to prevent AttributeError (#20518)
This commit is contained in:
+10
-2
@@ -16,7 +16,7 @@ import warnings
|
|||||||
import weakref
|
import weakref
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from functools import wraps
|
from functools import cached_property, wraps
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from json import dumps
|
from json import dumps
|
||||||
from typing import Any, Callable, List, Optional, Tuple, Type, Union
|
from typing import Any, Callable, List, Optional, Tuple, Type, Union
|
||||||
@@ -140,8 +140,16 @@ class HttpResponse:
|
|||||||
def __init__(self, resp):
|
def __init__(self, resp):
|
||||||
self.resp = resp
|
self.resp = resp
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def _body(self):
|
||||||
|
return self.resp.read()
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
return json.loads(self.resp.read())
|
return json.loads(self._body)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def text(self):
|
||||||
|
return self._body.decode("utf-8", errors="replace")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def status_code(self):
|
def status_code(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user