python - 使用 Docker 和 GCloud Python API 访问 GS,无需 VM 上的服务帐户
问题描述
我需要从运行在 VM 中的 Docker 映像访问 Google Storage。我在没有服务帐户(安全原因)的情况下运行 VM,并启动安装了 GCloud Python API 的 Docker 映像。当我尝试在 GS 上连接时,在我的情况下读取一些原始数据时,它抛出了这个异常:
Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Engine metadata service. Status: 404
当我使用服务帐户启动 VM 时,我可以成功调用使用 GCP Python API。
代码不起作用的示例:
from google.cloud import storage
client = storage.Client()
for bucket in client.list_buckets():
print(bucket)
有人已经面临这个问题了吗?是否可以在没有服务帐户的情况下使用 GCP Python?
[Pyhton 库] https://google-cloud-python.readthedocs.io/en/latest/storage/client.html
谢谢,
解决方案
推荐阅读
- python - \n 拆分和获取不同输出时的问题
- sql - 插入插入到另一个表中的行的 p_key
- ms-access - MS Access 对传递查询的 SELECT 速度很慢
- html - 如何向工具提示内的文本添加超链接?
- php - Wordpress wp_insert_post 在创建新的自定义帖子时正在创建新的分类术语
- bazel - 如何从bazel查询和找出maven包的名称和版本?
- java - Spring批处理,添加新阅读器时出错
- sql-server - MS SQL Server 2019 从命令行导出数据库
- apache-kafka - Reactor Kafka 消费者在分区被撤销后继续消费消息
- python - 如何将动态值解析为 kv 文件中的属性?