python - 在没有凭据的情况下使用 Python Google Storage Client
问题描述
我正在使用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
该页面建议使用 Oath 或其他令牌,但我不应该需要这些,因为我的存储桶是公开的?我可以向 chrome 中的存储桶发出 HTTP 请求并接收数据。
我应该如何解决这个问题?我可以提供默认或空凭据吗?
解决方案
来自“云存储认证”:
您在 Cloud Storage 中执行的大部分操作都必须经过身份验证。唯一的例外是对允许匿名访问的对象的操作。
allUsers
如果组具有READ
权限,则可以匿名访问对象。该allUsers
组包括 Internet 上的任何人。
推荐阅读
- django-views - 使用 Django 中的 Boostrap 自动完成模型形式的外键字段
- python - Boxlayout 未在屏幕上显示按钮
- javascript - 谷歌分析代码的改编不是注册页面浏览量
- python - 如何定义浏览器异步点击使用?
- javascript - How to make impossible rewriting Class instances fields
- javascript - 如何将动态 Javascript 元素从网站导入 Google 表格
- pgadmin - 如何打开 pgadmin 脚本
- c - c语言,5的倍数保存在素数向量上
- python-3.x - 使用 add_widget 生成 TextInput 并稍后在 Kivy、Python 上引用它,没有 id
- python-3.x - 用于运行配置的 Python VSCode 设置