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