From a3b4d673626141ca05cd6e85e3c81597d0efcd8c Mon Sep 17 00:00:00 2001 From: "ran.liao" Date: Fri, 6 Dec 2024 16:24:51 +0900 Subject: [PATCH] Reset token to empty string --- python/mujinwebstackclient/controllerwebclientraw.py | 8 ++++++-- python/mujinwebstackclient/webstackclient.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/python/mujinwebstackclient/controllerwebclientraw.py b/python/mujinwebstackclient/controllerwebclientraw.py index 7219364..468ae79 100644 --- a/python/mujinwebstackclient/controllerwebclientraw.py +++ b/python/mujinwebstackclient/controllerwebclientraw.py @@ -258,5 +258,9 @@ def CallGraphAPI(self, query, variables=None, headers=None, timeout=5.0): return content['data'] def UpdateJsonWebToken(self, jsonWebToken): - self._session.auth = None - self._headers['Authorization'] = 'Bearer ' + jsonWebToken + if jsonWebToken == '': + self._session.auth = None + self._headers['Authorization'] = 'Bearer ' + jsonWebToken + else: + self._session.auth = requests_auth.HTTPBasicAuth(self._username, self._password) + self._headers.pop('Authorization', None) diff --git a/python/mujinwebstackclient/webstackclient.py b/python/mujinwebstackclient/webstackclient.py index 91cef8a..2659147 100644 --- a/python/mujinwebstackclient/webstackclient.py +++ b/python/mujinwebstackclient/webstackclient.py @@ -206,10 +206,12 @@ def Login(self, timeout=5): """ try: self.jsonWebToken = self.graphApi.Login(username=self.controllerusername, password=self.controllerpassword, fields={'jsonWebToken': None})['jsonWebToken'] - self._webclient.UpdateJsonWebToken(self.jsonWebToken) except Exception as e: + self.jsonWebToken = '' log.debug('failed to login through graphql api, use basic HTTP authorization: %s', e) self.Ping(timeout=timeout) + finally: + self._webclient.UpdateJsonWebToken(self.jsonWebToken) def Ping(self, timeout=5): """Sends a dummy HEAD request to api endpoint