【问题标题】:How to solve the ThresholdRule TypeError while using google-cloud-billing-budgets library如何在使用 google-cloud-billing-budgets 库时解决 ThresholdRule TypeError
【发布时间】: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


【解决方案1】:

终于可以解决了。这是解决方案:

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

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

【讨论】:

  • 既然您的问题已经解决,您能否接受您发布的解决方案?
猜你喜欢
  • 2018-04-14
  • 1970-01-01
  • 1970-01-01
  • 2022-10-03
  • 1970-01-01
  • 2020-03-23
  • 1970-01-01
  • 2017-12-27
  • 1970-01-01
相关资源
最近更新 更多