【发布时间】:2018-12-18 22:19:29
【问题描述】:
该项目是由 Python 使用 google_application_defaults 创建的,计费 API 已成功激活并在命令行上使用
os.system(gcloud services enable cloudbilling.googleapis.com)
os.system(gcloud services list --enabled)
然后,运行时:
from googleapiclient import discovery, errors, logging
CB = discovery.build("cloudbilling", "v1", credentials = default_creds, cache_discovery = False)
billing_body = {"projectID": projectID, "name": "projects/"+projectID+"/billingInfo", "billingEnabled": True, "billingAccountName": "billingAccounts/"+billingAccount}
billingUP = CB.projects().updateBillingInfo(name = projectID, body = billing_body )
try:
billing_resp = billingUP.execute()
print("Billing succesfully enabled")
except errors.HttpError as err:
billing_resp = None
print("request voided")
logging.error("There was an error creating the project. Check:")
logging.error(err._get_reason())
我收到以下错误:
Cloud Billing API has not been used in project XXXXXXXXXX before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=XXXXXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
我也尝试在 python 脚本之外的命令行上直接激活它,但错误仍然存在。我已经在 billingUp 请求的“projectID”部分使用了不同的格式:projectName、projects/projectName、projectID、projects/projectID,但没有任何效果。任何可能的解决方案?
【问题讨论】:
-
是否确实启用了计费,但尚未传播?
-
试试这个命令:
gcloud beta billing accounts list如果这报告了一个 API 错误,你还没有启用计费。如果它有效,那么您有代码问题,或者您没有等待足够长的时间来启用 API。 -
@JohnHanley 该命令正常工作,显示帐户名称、ID 和状态。
-
@DustinIngram Uhm,我对此表示怀疑,因为我已经尝试了两天。
-
验证项目帐号是否与您正在使用的服务帐户凭据的项目匹配。
标签: python google-cloud-platform gcloud google-api-client