如何解决使用googlecloudbillingbudgets库时的ThresholdRule类型错误

2024-05-13 02:03:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用google-cloud-billing-budgets自动创建预算,但在尝试创建阈值规则时出错。 我的代码看起来像这样

    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,但它没有给我任何暗示


Tags: 代码cloudnewthreshold规则google阈值details
1条回答
网友
1楼 · 发布于 2024-05-13 02:03:32

最后,我可以解决它。这就是解决方案:

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

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

相关问题 更多 >