diff --git a/apps/third/king/k.py b/apps/third/king/k.py index 73f39bfc..3de05a8f 100644 --- a/apps/third/king/k.py +++ b/apps/third/king/k.py @@ -35,15 +35,16 @@ class KingClient(HandleLogMixin): # is_ok, _ = self.request(**kapis['heartbeat'], raise_exception=False, timeout=10) # if is_ok == 'success': # return - json = { - 'username': settings.KING_USERNAME, - 'password': settings.KING_PASSWORD - } - cache.set('king_token_request', 'requesting') - _, res = self.request( - **kapis['login'], json=json, timeout=10) - cache.set('king_token', res['Authorization'], timeout=None) - cache.set('king_token_request', 'done') + if cache.get('king_token_request', None) != 'requesting': + json = { + 'username': settings.KING_USERNAME, + 'password': settings.KING_PASSWORD + } + cache.set('king_token_request', 'requesting') + _, res = self.request( + **kapis['login'], json=json, timeout=10) + cache.set('king_token', res['Authorization'], timeout=None) + cache.set('king_token_request', 'done') def request(self, url: str, method: str = 'post', params=dict(), json=dict(), timeout=20, raise_exception=True): if not self.king_enabled: