【发布时间】:2021-10-06 05:38:36
【问题描述】:
我正在使用 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
我一直在关注documentation,但它并没有给我任何提示。
【问题讨论】:
-
尝试使用这个 'threshold_percent' : 0.9 而不是 'threshold_percent' : [0.9] (因为我们在方括号中传递值可能会将值视为列表)。
-
我这样做了,但我收到了这个错误
TypeError: Value must be iterable -
尝试使用 'threshold_percent' : 0.9, 或尝试使用这个 'threshold_percent' : (0.9, )
-
解决方案不存在,我必须在
new_thresholde_rule中使用括号,所以我将拥有这个[new_thresholde_rule]
标签: python google-cloud-platform google-cloud-billing