我正在使用Python Google Storage Client,但是我正在使用具有公共读/写访问权限的存储桶。 (我知道这通常是一个可怕的想法,但我有一个罕见的用例,它很好)。
当我尝试检索一些文件时,我得到了一个DefaultCredentialsError
。
BUCKET_NAME = 'my-public-bucket-name'
storage_client = storage.Client()
bucket = storage_client.get_bucket(BUCKET_NAME)
def list_blobs(prefix, delimiter=None):
blobs = bucket.list_blobs(prefix=prefix, delimiter=delimiter)
print('Blobs:')
for blob in blobs:
print(blob.name)
具体错误如下:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
该页面建议使用誓言或其他令牌,但我不应该需要这些,因为我的桶是公开的?我可以在chrome中向存储桶发出HTTP请求并接收数据。
我应该如何解决这个问题?我可以提供默认凭证或空凭证吗?
来自“Cloud Storage Authentication”:
您在云存储中执行的大多数操作都必须经过身份验证。唯一的例外是对允许匿名访问的对象的操作。如果
allUsers
组具有READ
权限,则可以匿名访问对象。allUsers
组包括互联网上的任何人。