2 回答

TA貢獻1993條經(jīng)驗 獲得超6個贊
答案是信譽確實是錯誤的,但是當我嘗試在客戶端client.bucket(bucket_name)
而不是client.get_bucket(bucket_name)
.

TA貢獻1815條經(jīng)驗 獲得超13個贊
請按照以下步驟正確設置適用于 Python 的 Cloud Storage 客戶端庫。通常,云存儲庫可以使用應用程序默認憑據(jù)或環(huán)境變量進行身份驗證。
請注意,推薦使用的方法是使用環(huán)境變量設置身份驗證(即,如果您使用的是 Linux:export GOOGLE_APPLICATION_CREDENTIALS="/path/to/[service-account-credentials].json"應該可行)并完全避免使用該service_account.Credentials.from_service_account_info()方法:
from google.cloud import storage
storage_client = storage.Client(project='project-id-where-the-bucket-is')
bucket_name = "your-bucket"
bucket = client.get_bucket(bucket_name)
應該可以簡單地工作,因為身份驗證是由客戶端庫通過環(huán)境變量處理的。
現(xiàn)在,如果您有興趣顯式使用服務帳戶而不是使用service_account.Credentials.from_service_account_info()方法,您可以通過from_service_account_json()以下方式直接使用該方法:
from google.cloud import storage
# Explicitly use service account credentials by specifying the private key
# file.
storage_client = storage.Client.from_service_account_json(
'/[service-account-credentials].json')
bucket_name = "your-bucket"
bucket = client.get_bucket(bucket_name)
在此處查找有關如何向您的應用程序提供憑據(jù)的所有相關詳細信息。
添加回答
舉報