Python 在没有服务帐户的情况下使用google cloud sdk进行身份验证
从本地的jupyter笔记本运行 我尝试使用以下代码从GCP存储桶下载一个文件,这是一项非常简单的任务:Python 在没有服务帐户的情况下使用google cloud sdk进行身份验证,python,authentication,google-cloud-storage,google-cloud-sdk,Python,Authentication,Google Cloud Storage,Google Cloud Sdk,从本地的jupyter笔记本运行 我尝试使用以下代码从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") # Cre
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")
重要的是,我想使用我的最终用户帐户,但不能使用服务帐户。我发现谷歌令人难以置信地困惑。有人能告诉我从哪里获取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()
它将从环境中获取凭据
或者,您也可以通过OAuth同意屏幕生成客户端密码。最简单的方法是运行
gcloud auth application-default login
然后在脚本中:
storage_client = storage.Client()
它将从环境中获取凭据
或者,您可以通过OAuth同意屏幕生成客户机密。谢谢,这是我一直在寻找的非常简单的解决方案……谢谢,这是我一直在寻找的非常简单的解决方案。。。