Skip to content

Commit 3827cd8

Browse files
authored
GCE creds fix (#192)
1 parent d7eb885 commit 3827cd8

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Unreleased (2022-01-05)
44

55
- Fixed error when "directories" created on AWS S3 were reported as files. ([Issue #148](https://github.com/drivendataorg/cloudpathlib/issues/148), [PR #190](https://github.com/drivendataorg/cloudpathlib/pull/190))
6-
6+
- Fixed bug where GCE machines can instantiate default client, but we don't attempt it. ([Issue #191](https://github.com/drivendataorg/cloudpathlib/issues/191)
77

88
## v0.6.4 (2021-12-29)
99

cloudpathlib/gs/gsclient.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
if TYPE_CHECKING:
1212
from google.auth.credentials import Credentials
1313

14+
from google.auth.exceptions import DefaultCredentialsError
1415
from google.cloud.storage import Client as StorageClient
1516

17+
1618
except ModuleNotFoundError:
1719
implementation_registry["gs"].dependencies_loaded = False
1820

@@ -74,7 +76,10 @@ def __init__(
7476
elif application_credentials is not None:
7577
self.client = StorageClient.from_service_account_json(application_credentials)
7678
else:
77-
self.client = StorageClient.create_anonymous_client()
79+
try:
80+
self.client = StorageClient()
81+
except DefaultCredentialsError:
82+
self.client = StorageClient.create_anonymous_client()
7883

7984
super().__init__(local_cache_dir=local_cache_dir)
8085

0 commit comments

Comments
 (0)