三方接口处理问题

This commit is contained in:
曹前明 2022-10-03 21:50:05 +08:00
parent 574254f7bc
commit 7e9d5fe7b0
3 changed files with 24 additions and 17 deletions

View File

@ -77,13 +77,18 @@ class DhClient:
if params:
url = url.format(**params)
self.log.update({"path": url})
if self.isGetingToken:
wait_num = 0
while self.isGetingToken and wait_num < 3:
time.sleep(0.5)
wait_num = wait_num + 1
r = getattr(requests, method)('{}{}'.format(settings.DAHUA_BASE_URL, url),
headers=self.headers, params=params, json=json,
timeout=timeout, files=files, verify=False)
# if settings.DEBUG:
# print_roundtrip(r)
ret = r.text
if r.status_code == 200:
if 300 > r.status_code >= 200:
ret = r.json()
if ret['code'] not in ['0', '100', '00000', '1000', 0, 100, 1000]:
detail = '大华错误:' + \

View File

@ -73,13 +73,18 @@ class SpClient:
files = {'file': open(settings.BASE_DIR + file_path_rela, 'rb')}
if params:
url = url.format(**params)
if self.isGetingToken:
wait_num = 0
while self.isGetingToken and wait_num < 3:
time.sleep(0.5)
wait_num = wait_num + 1
r = getattr(requests, method)('{}{}'.format(settings.SP_BASE_URL, url),
headers=self.headers, params=params, json=json,
timeout=timeout, files=files, verify=False)
# if settings.DEBUG:
# print_roundtrip(r)
ret = r.text
if r.status_code == 200:
if 300 > r.status_code >= 200:
ret = r.json()
if 'code' in ret and ret['code'] not in ['0', '100', '00000', '1000', 0, 100, 1000]:
detail = '音响错误:{}'.format(str(ret.get('msg', '')))

View File

@ -68,25 +68,22 @@ class XxClient:
json['licence'] = settings.XX_LICENCE
self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method,
"params": params, "body": json, "target": "xunxi", "result": 10, "headers": self.headers}
# if self.isGetingToken:
# req_num = 0
# while True:
# time.sleep(0.5)
# if not self.isGetingToken:
# self.request(url, method, params, json, timeout, raise_exception)
# req_num = req_num + 1
# if req_num > 4:
# break
# else:
if self.isGetingToken:
wait_num = 0
while self.isGetingToken and wait_num < 3:
time.sleep(0.5)
wait_num = wait_num + 1
r = getattr(requests, method)('{}{}'.format(settings.XX_BASE_URL, url),
headers=self.headers, params=params, json=json, timeout=timeout, verify=False)
# if settings.DEBUG:
# print_roundtrip(r)
ret = r.text
if 300 > r.status_code >= 200:
ret = r.json()
if ret.get('errorCode') in ['1060000', 1060000]:
self._get_token() # 重新获取token
self.request(url, method, params, json, timeout, raise_exception) # 重新请求
else:
# if ret.get('errorCode') in ['1060000', 1060000]:
# self._get_token() # 重新获取token
# self.request(url, method, params, json, timeout, raise_exception) # 重新请求
# else:
if ret['errorCode'] != 0:
err_detail = dict(detail='寻息错误:' + '|'.join(ret['errorMsg']),
code='xx_' + str(ret['errorCode']))