Sye*_*mad 6 python google-cloud-storage google-cloud-platform
我在谷歌云存储上做了一个可公开列出的存储桶。如果我尝试在浏览器中列出存储桶对象,我可以看到所有键。我试图使用该create_anonymous_client()函数,以便我可以在 python 脚本中列出存储桶键。它给了我一个例外。我到处查找,仍然找不到使用该功能的正确方法。
from google.cloud import storage
client = storage.Client.create_anonymous_client()
a = client.lookup_bucket('publically_listable_bucket')
a.list_blobs()
Run Code Online (Sandbox Code Playgroud)
我得到的例外:
ValueError: Anonymous credentials cannot be refreshed.
Run Code Online (Sandbox Code Playgroud)
附加查询:我可以使用 列出和下载公共谷歌云存储桶的内容boto3,如果是,如何匿名进行?
此错误意味着您尝试列出的存储桶未授予正确的权限。您必须将“Storage Object Viewer”或“Storage Legacy Bucket Reader”角色授予“allUsers”。