[英]Authenticating with google cloud sdk without service account
Running from a local jupyter notebook.从本地 jupyter 笔记本运行。
I am trying to do the very simple task of downloading a file from a GCP storage bucket using the following code:我正在尝试使用以下代码执行从 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")
Importantly I want to use my end-user account and cannot use a service account.重要的是,我想使用我的最终用户帐户并且不能使用服务帐户。 I am finding the google docs incredibly confusing.
我发现谷歌文档令人难以置信的混乱。 Could someone please tell me where to get the gcp json key and whether it is as simple as the code snippet above or whether I have to add some intermediary steps?
有人可以告诉我在哪里可以获得 gcp json 密钥,它是否像上面的代码片段一样简单,或者我是否必须添加一些中间步骤?
When I follow the linked docs I get sent to an OAuth portal and when I login through google I get this error message:当我关注链接的文档时,我被发送到 OAuth 门户网站,当我通过谷歌登录时,我收到以下错误消息:
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
The easiest would be to just run最简单的就是运行
gcloud auth application-default login
And then in the script just:然后在脚本中:
storage_client = storage.Client()
And it will get the credentials from the environment.它将从环境中获取凭据。
Alternatively, you can follow this doc to go through the OAuth consent screen and generate a client secret.或者,您可以通过 OAuth 同意屏幕按照此文档访问 go 并生成客户端密码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.