pythongoogle-cloud-platformgoogle-cloud-billing

How to solve the ThresholdRule TypeError while using google-cloud-billing-budgets library


I'm using google-cloud-billing-budgets to automatically create budgets, but I'm getting errors when I try to create the ThresholdRule. My code looks like this.

    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,
        }
    )

The error is this:

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

I have been following the documentation, but it did not give me any hint.


Solution

  • Finally, I can solve it. This is the solution:

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

    I have to use brackets in 'threshold_rules': [new_thresholde_rule], that's all. It's working.