![](/img/trans.png)
[英]Is there a supported way to authenticate a service account using the Google cloud Python SDK without using a keyfile?
[英]Authenticating with google cloud sdk without service account
從本地 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")
# 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 門戶網站,當我通過谷歌登錄時,我收到以下錯誤消息:
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 同意屏幕按照此文檔訪問 go 並生成客戶端密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.