With GOOGLE_APPLICATION_CREDENTIALS not set on gce instances, cloudpathlib operations such as is_dir fail:
from cloudpathlib import CloudPath
p = CloudPath("gs://<some non-public path>")
p.is_dir()
fails with:
/lib/python3.7/site-packages/google/auth/credentials.py in refresh(self, request)
171 """Raises :class:`ValueError``, anonymous credentials cannot be
172 refreshed."""
--> 173 raise ValueError("Anonymous credentials cannot be refreshed.")
174
175 def apply(self, headers, token=None):
ValueError: Anonymous credentials cannot be refreshed
On gce instances, storage client doesn't need any further auth setup. For eg., without GOOGLE_APPLICATION_CREDENTIALS set, this works:
from google.cloud import storage
storage_client = storage.Client()
# Make an authenticated API request
buckets = list(storage_client.list_buckets())
print(buckets)
and this also works:
from cloudpathlib import CloudPath
from google.cloud import storage
gs_client = cloudpathlib.GSClient(storage_client=storage.Client())
gs_client.set_as_default_client()
p = CloudPath("gs://<some non-public path>")
p.is_dir()
It would be nice if this extra setup is not needed.
Maybe while constructing it can try creating non-anonymous storage client and if it fails create anonymous one.
With GOOGLE_APPLICATION_CREDENTIALS not set on gce instances, cloudpathlib operations such as
is_dirfail:fails with:
On gce instances, storage client doesn't need any further auth setup. For eg., without GOOGLE_APPLICATION_CREDENTIALS set, this works:
and this also works:
It would be nice if this extra setup is not needed.
Maybe while constructing it can try creating non-anonymous storage client and if it fails create anonymous one.