Skip to content

Commit

Permalink
Refresh credentials to check validity
Browse files Browse the repository at this point in the history
The original call to credentials.valid does not work until the
credential has been refreshed once, as discussed in #486. This
instead checks if the credential will work by trying to connect
  • Loading branch information
baxen committed Sep 16, 2022
1 parent 5255214 commit 8100697
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gcsfs/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ def _connect_google_default(self):

def _connect_cloud(self):
self.credentials = gauth.compute_engine.Credentials()

if not self.credentials.valid:
raise ValueError("Invalid gcloud credentials")
try:
with requests.Session() as session:
req = Request(session)
self.credentials.refresh(req)
except gauth.exceptions.RefreshError as error:
raise ValueError("Invalid gcloud credentials") from error

def _connect_cache(self):

Expand Down

0 comments on commit 8100697

Please sign in to comment.