From 538acb4c46e002738b9abd3e56571b9b773cc627 Mon Sep 17 00:00:00 2001 From: shuwenn <47200617+alphabetc1@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:59:32 +0800 Subject: [PATCH] fix: Add .text property to HttpResponse to prevent AttributeError (#20518) --- python/sglang/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/sglang/utils.py b/python/sglang/utils.py index 751d1af33..1a6187d91 100644 --- a/python/sglang/utils.py +++ b/python/sglang/utils.py @@ -16,7 +16,7 @@ import warnings import weakref from collections import OrderedDict from concurrent.futures import ThreadPoolExecutor -from functools import wraps +from functools import cached_property, wraps from io import BytesIO from json import dumps from typing import Any, Callable, List, Optional, Tuple, Type, Union @@ -140,8 +140,16 @@ class HttpResponse: def __init__(self, resp): self.resp = resp + @cached_property + def _body(self): + return self.resp.read() + 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 def status_code(self):