【发布时间】:2023-03-04 02:45:01
【问题描述】:
我在谷歌云存储上创建了一个可公开列出的存储桶。如果我尝试在浏览器中列出存储桶对象,我可以看到所有键。我试图使用 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()
我得到的异常:
ValueError: Anonymous credentials cannot be refreshed.
补充查询:我可以使用boto3列出和下载公共谷歌云存储桶的内容吗?如果可以,如何匿名?
【问题讨论】:
-
如文档所述:“Boto 是适用于 Python 的 Amazon Web Services (AWS) 开发工具包”因此它不是为 Google 相关服务而设计的,您最好使用专为他们设计的图书馆。来源:boto3.readthedocs.io/en/latest/index.html
标签: python google-cloud-platform google-cloud-storage