fix: kingClient get_token request 3
This commit is contained in:
parent
41c79c1fdd
commit
1a2baa82d9
|
@ -42,21 +42,22 @@ 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('亚控对接未启用')
|
||||||
count = 6
|
if check_auth:
|
||||||
while cache.get('king_token_request') == 'requesting':
|
count = 6
|
||||||
time.sleep(0.5)
|
while cache.get('king_token_request') == 'requesting':
|
||||||
if cache.get('king_token_request') == 'done':
|
time.sleep(0.5)
|
||||||
break
|
if cache.get('king_token_request') == 'done':
|
||||||
count = count - 1
|
break
|
||||||
if count < 0:
|
count = count - 1
|
||||||
break
|
if count < 0:
|
||||||
|
break
|
||||||
self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method,
|
self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method,
|
||||||
"params": params, "body": json, "target": "king", "result": 10, "headers": self.headers}
|
"params": params, "body": json, "target": "king", "result": 10, "headers": self.headers}
|
||||||
try:
|
try:
|
||||||
|
@ -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