From 542c2d26605a958ec0c244b8b36e4ac3225f3363 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 14 Oct 2025 15:59:42 +0800 Subject: [PATCH] bugfix --- uapi/appapi.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/uapi/appapi.py b/uapi/appapi.py index 68872e5..18e6626 100644 --- a/uapi/appapi.py +++ b/uapi/appapi.py @@ -177,6 +177,7 @@ class UAPI: gen = liner(self.__call__(upappid, apiname, callerid, params=params)) async for line in gen: debug(f'{line=},{type(line)=}') + respline = line line = line.decode('utf-8') filter = self.uapi.chunk_match if not filter: @@ -189,7 +190,7 @@ class UAPI: line = await self.rendertmpl(self.uapi.response, dic) line = self.filter_nl_cr(line) except Exception as e: - debug(f'{line=}, {self.uapi.response=} error({e})\n{format_exc()}') + debug(f'{respline=}, {line=}, {self.uapi.response=} error({e})\n{format_exc()}') continue if len(line): yield f'{line}\n' @@ -201,9 +202,12 @@ class UAPI: async for chunk in self.__call__(upappid, apiname, callerid, params=params): b += chunk if self.uapi.response: - dic = json.loads(b.decode('utf-8')) - s = await self.rendertmpl(self.uapi.response, dic) - b = s.encode('utf-8') + try: + dic = json.loads(b.decode('utf-8')) + s = await self.rendertmpl(self.uapi.response, dic) + b = s.encode('utf-8') + except Exception as e: + debug('http.response={b}, response_template={self.uapi.response}, error={e}') return b async def do_auth(self, auth_uapi):