在没有服务帐户的情况下使用 google 云 SDK 进行身份验证
Authenticating with google cloud sdk without service account
运行 来自本地 jupyter notebook。
我正在尝试执行非常简单的任务,即使用以下代码从 GCP 存储桶下载文件:
from google.cloud import storage
# Initialise a client
storage_client = storage.Client("gcpkey.json")
# Create a bucket object for our bucket
bucket = storage_client.get_bucket("gcp_bucket")
# Create a blob object from the filepath
blob = bucket.blob("file_in_bucket_I_want.file")
# Download the file to a destination
blob.download_to_filename("destination_file_name")
重要的是,我想使用我的最终用户帐户,不能使用服务帐户。我发现 google docs 令人难以置信的混乱。有人可以告诉我从哪里获得 gcp json 密钥,它是否像上面的代码片段一样简单,或者我是否必须添加一些中间步骤?
当我关注链接文档时,我被发送到 OAuth 门户,当我通过 google 登录时,我收到此错误消息:
This app isn't verified
This app hasn't been verified by Google yet. Only proceed if you know and trust the developer.
If you’re the developer, submit a verification request to remove this screen. Learn more
最简单的就是 运行
gcloud auth application-default login
然后在脚本中:
storage_client = storage.Client()
并且它将从环境中获取凭据。
或者,您可以按照 this doc 通过 OAuth 同意屏幕并生成客户端密码。
运行 来自本地 jupyter notebook。
我正在尝试执行非常简单的任务,即使用以下代码从 GCP 存储桶下载文件:
from google.cloud import storage
# Initialise a client
storage_client = storage.Client("gcpkey.json")
# Create a bucket object for our bucket
bucket = storage_client.get_bucket("gcp_bucket")
# Create a blob object from the filepath
blob = bucket.blob("file_in_bucket_I_want.file")
# Download the file to a destination
blob.download_to_filename("destination_file_name")
重要的是,我想使用我的最终用户帐户,不能使用服务帐户。我发现 google docs 令人难以置信的混乱。有人可以告诉我从哪里获得 gcp json 密钥,它是否像上面的代码片段一样简单,或者我是否必须添加一些中间步骤?
当我关注链接文档时,我被发送到 OAuth 门户,当我通过 google 登录时,我收到此错误消息:
This app isn't verified
This app hasn't been verified by Google yet. Only proceed if you know and trust the developer.
If you’re the developer, submit a verification request to remove this screen. Learn more
最简单的就是 运行
gcloud auth application-default login
然后在脚本中:
storage_client = storage.Client()
并且它将从环境中获取凭据。
或者,您可以按照 this doc 通过 OAuth 同意屏幕并生成客户端密码。