bugfix
This commit is contained in:
parent
e636fbd81b
commit
817a2b9639
@ -123,13 +123,13 @@ class UAPI:
|
|||||||
self.auth_ret = None
|
self.auth_ret = None
|
||||||
self.sor = sor
|
self.sor = sor
|
||||||
|
|
||||||
def rendertmpl(self, tmplstr, params={}):
|
async def rendertmpl(self, tmplstr, params={}):
|
||||||
if tmplstr is None:
|
if tmplstr is None:
|
||||||
return None
|
return None
|
||||||
ns = self.env.copy()
|
ns = self.env.copy()
|
||||||
ns.update(params)
|
ns.update(params)
|
||||||
te = MyTemplateEngine([], env=self.env)
|
te = self.env.tmpl_engine
|
||||||
return te.renders(tmplstr, ns)
|
return await te.renders(tmplstr, ns)
|
||||||
|
|
||||||
async def get_uapis(self, sor, upappid, apiname, callerid, params={}):
|
async def get_uapis(self, sor, upappid, apiname, callerid, params={}):
|
||||||
self.env.update(params)
|
self.env.update(params)
|
||||||
@ -186,7 +186,7 @@ class UAPI:
|
|||||||
if self.uapi.response:
|
if self.uapi.response:
|
||||||
try:
|
try:
|
||||||
dic = json.loads(line)
|
dic = json.loads(line)
|
||||||
line = 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'{line=}, {self.uapi.response=} error({e})\n{format_exc()}')
|
||||||
@ -202,7 +202,7 @@ class UAPI:
|
|||||||
b += chunk
|
b += chunk
|
||||||
if self.uapi.response:
|
if self.uapi.response:
|
||||||
dic = json.loads(b.decode('utf-8'))
|
dic = json.loads(b.decode('utf-8'))
|
||||||
s = self.rendertmpl(self.uapi.response, dic)
|
s = await self.rendertmpl(self.uapi.response, dic)
|
||||||
b = s.encode('utf-8')
|
b = s.encode('utf-8')
|
||||||
return b
|
return b
|
||||||
|
|
||||||
@ -212,22 +212,22 @@ class UAPI:
|
|||||||
b+= chunk
|
b+= chunk
|
||||||
d = json.loads(b.encode('utf-8'))
|
d = json.loads(b.encode('utf-8'))
|
||||||
if auth_uapi.response:
|
if auth_uapi.response:
|
||||||
s = self.rendertmpl(auth_uapi.response, d)
|
s = await self.rendertmpl(auth_uapi.response, d)
|
||||||
d = json.loads(s)
|
d = json.loads(s)
|
||||||
self.env.update(d)
|
self.env.update(d)
|
||||||
return
|
return
|
||||||
|
|
||||||
async def stream_resp(self, api):
|
async def stream_resp(self, api):
|
||||||
path = self.rendertmpl(api.path)
|
path = await self.rendertmpl(api.path)
|
||||||
url = self.env.get('baseurl') + path
|
url = self.env.get('baseurl') + path
|
||||||
method = api.httpmethod
|
method = api.httpmethod
|
||||||
headers = self.rendertmpl(api.headers)
|
headers = await self.rendertmpl(api.headers)
|
||||||
try:
|
try:
|
||||||
headers = json.loads(headers)
|
headers = json.loads(headers)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception(f'{e}, {headers=},{api.headers=}')
|
exception(f'{e}, {headers=},{api.headers=}')
|
||||||
raise e
|
raise e
|
||||||
body = self.rendertmpl(api.data)
|
body = await self.rendertmpl(api.data)
|
||||||
if body:
|
if body:
|
||||||
try:
|
try:
|
||||||
bdy = json.loads(body)
|
bdy = json.loads(body)
|
||||||
@ -235,7 +235,7 @@ class UAPI:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception(f'{e}, {body=},{api.data=}')
|
exception(f'{e}, {body=},{api.data=}')
|
||||||
body = None
|
body = None
|
||||||
_params = self.rendertmpl(api.params)
|
_params = await self.rendertmpl(api.params)
|
||||||
if _params:
|
if _params:
|
||||||
_params = json.loads(_params)
|
_params = json.loads(_params)
|
||||||
debug(f'{headers=}, {body=}. {method=}, {url=}')
|
debug(f'{headers=}, {body=}. {method=}, {url=}')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user