This commit is contained in:
yumoqing 2024-02-29 18:49:03 +08:00
parent d60ff4b2b3
commit 79c04c340e
2 changed files with 21 additions and 14 deletions

View File

@ -56,7 +56,7 @@ class HttpClient:
print(f'=====domain={domain},cookies={fltered},type={type(fltered)}===') print(f'=====domain={domain},cookies={fltered},type={type(fltered)}===')
async def request(self, url, method, async def request(self, url, method,
resp_type=RESPONSE_TEXT, response_type=RESPONSE_TEXT,
params=None, params=None,
data=None, data=None,
json=None, json=None,
@ -69,7 +69,7 @@ class HttpClient:
json=json, json=json,
headers=headers, **kw) headers=headers, **kw)
if resp.status==200: if resp.status==200:
return await self.handleResponse(url, resp, resp_type) return await self.handleResp(url, resp, response_type)
return None return None
async def get(self,url,**kw): async def get(self,url,**kw):

View File

@ -8,12 +8,12 @@ class OAuthClient:
assert desc.get('mapis') assert desc.get('mapis')
self.desc = desc self.desc = desc
self.data = desc.get('data') self.data = desc.get('data')
self.mapis = desc.get(mapis) self.mapis = desc.get('mapis')
self.mkeys = self.mapis.keys() self.mkeys = self.mapis.keys()
self.ac = ArgsConvert('${', '}') self.ac = ArgsConvert('${', '}')
aysnc def __call__(self, mapi, params): async def __call__(self, mapi, params):
if mapi not in self.mkeys: if mapi not in self.mkeys:
raise Exception(f'{mapi} not defined') raise Exception(f'{mapi} not defined')
d = self.mapis[mapi] d = self.mapis[mapi]
@ -24,21 +24,28 @@ class OAuthClient:
headers[h.get('name')] = h.get('value') headers[h.get('name')] = h.get('value')
myparams = {} myparams = {}
for p in d.get('params', {}): for p in d.get('params', {}):
myparams[[p.get('name')] = p.get('value') myparams[p.get('name')] = p.get('value')
url = d.get('url') url = d.get('url')
_params = self.datalize(myparams, params) _params = self.datalize(myparams, params)
_headers = self.datalize(headers, params) _headers = self.datalize(headers, params)
response_type = d.get('response_type', RESPONSE_JSON)
hc = HttpClient() hc = HttpClient()
resp_data = hc.request(url, method, response_type=resp_type, resp_data = await hc.request(url, method, response_type=response_type,
params=params, params=_params,
headers=headers) headers=_headers)
respdesc= d.get('response', []) if resp_data is None:
raise Exception(f'request error:{url=}\n{method=}\n{response_type=}\n{_params=}\n{_headers=}')
errfield = d.get('error_field')
err = resp_data.get(errfield)
if err:
msg = resp_data.get(d.get('error_msg_field'))
raise Exception(f'Error:{url}\n{msg}')
respdesc= d.get('resp_set_data', [])
for r in respdesc: for r in respdesc:
v = r['value'] v = resp_data[r['field']]
if v.startswith('${') and v.endswith('}'): k = r['name']
k = v[2:-1] self.data[k] = v
self.data[k] = resp_data[r['name']]
return resp_data return resp_data
def datalize(self, dic, data={}): def datalize(self, dic, data={}):