如何解决ThresholdRule类型错误,而使用谷歌云计费预算库



我使用google-cloud-billing-budgets来自动创建预算,但是当我尝试创建ThresholdRule时,我遇到了错误。我的代码是这样的:

new_thresholde_rule = budgets.ThresholdRule({
'threshold_percent' : [0.9]
})
new_budget_details = budgets.Budget({
'display_name': projectId,
'amount': new_amount,
'threshold_rules': new_thresholde_rule,
})
new_budget = client.create_budget(
request = {
'parent': BILLING_ACCOUNT,
'budget': new_budget_details,
}
)

错误如下:

TypeError: [0.9] has type list, but expected one of: int, long, float

我一直在看文档,但是它没有给我任何提示。

终于解出来了。解决方案如下:

new_budget_details = budgets.Budget({
'display_name': projectId,
'amount': new_amount,
'threshold_rules': [new_thresholde_rule],
})

我必须在'threshold_rules': [new_thresholde_rule]中使用括号,仅此而已。这是工作。

最新更新