This commit is contained in:
yumoqing 2025-10-14 15:59:42 +08:00
parent 817a2b9639
commit 542c2d2660

View File

@ -177,6 +177,7 @@ class UAPI:
gen = liner(self.__call__(upappid, apiname, callerid, params=params)) gen = liner(self.__call__(upappid, apiname, callerid, params=params))
async for line in gen: async for line in gen:
debug(f'{line=},{type(line)=}') debug(f'{line=},{type(line)=}')
respline = line
line = line.decode('utf-8') line = line.decode('utf-8')
filter = self.uapi.chunk_match filter = self.uapi.chunk_match
if not filter: if not filter:
@ -189,7 +190,7 @@ class UAPI:
line = await self.rendertmpl(self.uapi.response, dic) line = await self.rendertmpl(self.uapi.response, dic)
line = self.filter_nl_cr(line) line = self.filter_nl_cr(line)
except Exception as e: 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 continue
if len(line): if len(line):
yield f'{line}\n' yield f'{line}\n'
@ -201,9 +202,12 @@ class UAPI:
async for chunk in self.__call__(upappid, apiname, callerid, params=params): async for chunk in self.__call__(upappid, apiname, callerid, params=params):
b += chunk b += chunk
if self.uapi.response: if self.uapi.response:
try:
dic = json.loads(b.decode('utf-8')) dic = json.loads(b.decode('utf-8'))
s = await self.rendertmpl(self.uapi.response, dic) s = await self.rendertmpl(self.uapi.response, dic)
b = s.encode('utf-8') b = s.encode('utf-8')
except Exception as e:
debug('http.response={b}, response_template={self.uapi.response}, error={e}')
return b return b
async def do_auth(self, auth_uapi): async def do_auth(self, auth_uapi):