From 04c509db124b083042044b3e64fde495bfd24760 Mon Sep 17 00:00:00 2001 From: Leo Dirac Date: Tue, 19 Nov 2024 14:19:39 -0800 Subject: [PATCH 1/2] Adding explicit timeout to whoami() --- src/groundlight/client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/groundlight/client.py b/src/groundlight/client.py index 07d64804..36435433 100644 --- a/src/groundlight/client.py +++ b/src/groundlight/client.py @@ -154,10 +154,12 @@ def __init__( self.image_queries_api = ImageQueriesApi(self.api_client) self.user_api = UserApi(self.api_client) self.labels_api = LabelsApi(self.api_client) + self.logged_in_user = "(not-logged-in)" self._verify_connectivity() def __repr__(self) -> str: - return f"Logged in as {self.whoami()} to Groundlight at {self.endpoint}" + # Don't call the API here because it that can get us stuck in a loop rendering exception strings + return f"Logged in as {self.logged_in_user} to Groundlight at {self.endpoint}" def _verify_connectivity(self) -> None: """ @@ -166,7 +168,7 @@ def _verify_connectivity(self) -> None: """ try: # a simple query to confirm that the endpoint & API token are working - self.whoami() + self.logged_in_user = self.whoami() if self._user_is_privileged(): logger.warning( "WARNING: The current user has elevated permissions. Please verify such permissions are necessary" @@ -204,7 +206,7 @@ def whoami(self) -> str: :return: str """ - obj = self.user_api.who_am_i() + obj = self.user_api.who_am_i(_request_timeout=DEFAULT_REQUEST_TIMEOUT) return obj["email"] def _user_is_privileged(self) -> bool: From 149bb66fd6b5ff01523242dd9f627a30708779f4 Mon Sep 17 00:00:00 2001 From: robotrapta <79607467+robotrapta@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:47:33 -0800 Subject: [PATCH 2/2] Update src/groundlight/client.py Co-authored-by: Brandon <132288221+brandon-groundlight@users.noreply.github.com> --- src/groundlight/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/groundlight/client.py b/src/groundlight/client.py index 36435433..b9c4ff98 100644 --- a/src/groundlight/client.py +++ b/src/groundlight/client.py @@ -158,7 +158,7 @@ def __init__( self._verify_connectivity() def __repr__(self) -> str: - # Don't call the API here because it that can get us stuck in a loop rendering exception strings + # Don't call the API here because that can get us stuck in a loop rendering exception strings return f"Logged in as {self.logged_in_user} to Groundlight at {self.endpoint}" def _verify_connectivity(self) -> None: