diff --git a/apps/third/king/k.py b/apps/third/king/k.py index 46636358..63ea4d85 100644 --- a/apps/third/king/k.py +++ b/apps/third/king/k.py @@ -42,21 +42,22 @@ class KingClient(HandleLogMixin): } cache.set('king_token_request', 'requesting', timeout=None) _, 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_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: raise ParseError('亚控对接未启用') - count = 6 - while cache.get('king_token_request') == 'requesting': - time.sleep(0.5) - if cache.get('king_token_request') == 'done': - break - count = count - 1 - if count < 0: - break + if check_auth: + count = 6 + while cache.get('king_token_request') == 'requesting': + time.sleep(0.5) + if cache.get('king_token_request') == 'done': + break + count = count - 1 + if count < 0: + break self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method, "params": params, "body": json, "target": "king", "result": 10, "headers": self.headers} try: @@ -69,9 +70,9 @@ class KingClient(HandleLogMixin): ret = r.json() if 'code' in ret: if ret['code'] != 0: - if ret['code'] in [-1, -2]: # 认证失败 + if ret['code'] in [-1, -2] and check_auth: # 认证失败 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 err_detail = dict(detail=f"亚控错误: {ret['message']}", code='king_' + str(ret['code']))