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 Aug 8, 2022
1 parent 1523233 commit 2d11b68
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gcsfs/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ 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:
self.credentials.refresh()
except gauth.exceptions.RefreshError as error:
raise ValueError("Invalid gcloud credentials") from error

def _connect_cache(self):

Expand Down

0 comments on commit 2d11b68

Please sign in to comment.