fix: kingClient get_token request 3
This commit is contained in:
parent
41c79c1fdd
commit
1a2baa82d9
|
@ -42,13 +42,14 @@ class KingClient(HandleLogMixin):
|
||||||
}
|
}
|
||||||
cache.set('king_token_request', 'requesting', timeout=None)
|
cache.set('king_token_request', 'requesting', timeout=None)
|
||||||
_, res = self.request(
|
_, res = self.request(
|
||||||
**kapis['login'], json=json, timeout=10)
|
**kapis['login'], json=json, timeout=10, check_auth=False)
|
||||||
cache.set('king_token', res['Authorization'], timeout=None)
|
cache.set('king_token', res['Authorization'], timeout=None)
|
||||||
cache.set('king_token_request', 'done', timeout=None)
|
cache.set('king_token_request', 'done', timeout=None)
|
||||||
|
|
||||||
def request(self, url: str, method: str = 'post', params=dict(), json=dict(), timeout=20, raise_exception=True):
|
def request(self, url: str, method: str = 'post', params=dict(), json=dict(), timeout=20, raise_exception=True, check_auth=True):
|
||||||
if not self.king_enabled:
|
if not self.king_enabled:
|
||||||
raise ParseError('亚控对接未启用')
|
raise ParseError('亚控对接未启用')
|
||||||
|
if check_auth:
|
||||||
count = 6
|
count = 6
|
||||||
while cache.get('king_token_request') == 'requesting':
|
while cache.get('king_token_request') == 'requesting':
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
@ -69,9 +70,9 @@ class KingClient(HandleLogMixin):
|
||||||
ret = r.json()
|
ret = r.json()
|
||||||
if 'code' in ret:
|
if 'code' in ret:
|
||||||
if ret['code'] != 0:
|
if ret['code'] != 0:
|
||||||
if ret['code'] in [-1, -2]: # 认证失败
|
if ret['code'] in [-1, -2] and check_auth: # 认证失败
|
||||||
self._get_token()
|
self._get_token()
|
||||||
self.request(url, method, params, json, timeout, raise_exception)
|
self.request(url, method, params, json, timeout, raise_exception, check_auth=False)
|
||||||
return
|
return
|
||||||
err_detail = dict(detail=f"亚控错误: {ret['message']}",
|
err_detail = dict(detail=f"亚控错误: {ret['message']}",
|
||||||
code='king_' + str(ret['code']))
|
code='king_' + str(ret['code']))
|
||||||
|
|
Loading…
Reference in New Issue