简体   繁体   English

在没有服务帐户的情况下使用谷歌云 sdk 进行身份验证

[英]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.

相关问题 是否有一种支持的方法可以在不使用密钥文件的情况下使用 Google Cloud Python SDK 对服务帐户进行身份验证? - Is there a supported way to authenticate a service account using the Google cloud Python SDK without using a keyfile? 验证 google.storage.Client 而不将服务帐户 JSON 保存到磁盘 - Authenticating a google.storage.Client without saving the service account JSON to disk 没有完整json文件的Google Cloud服务帐户身份验证 - Google Cloud service account auth without full json file 在 Cloud function 中生成没有密钥的谷歌服务帐户凭据 - Generate google service account credentials without key in Cloud function 带有服务帐户的Google Cloud Pub Sub - Google Cloud Pub Sub With Service Account Google云服务帐户VS. 最终用户帐户 - Google Cloud Service Account VS. End User Account 无法使用服务帐号对我的 Google Cloud Run 服务进行身份验证 - Cannot authenticate my Google Cloud Run service with a service account 使用 Bitbucket 管道对 GCP 服务帐户进行身份验证 - Authenticating GCP service account with Bitbucket Pipelines 将 Google Cloud 客户端/服务帐户机密 json 文件放在哪里? - Where to put Google Cloud client/service account secret json file? Google Cloud - 如何在应用程序代码中对用户而不是服务帐户进行身份验证? - Google Cloud - How to authenticate USER instead of a service account in app code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM