I am trying to fetch Azure Cost Usage data on daily basis using Python but I facing an error while trying to run the code
Error being generated : query_ops = client.operations.query AttributeError: 'Operations' object has no attribute 'query'
client = CostManagementClient(credentials, subscription_id)
# Query for yesterday's cost
query = "SELECT sum(cost) as cost FROM cost where time >= '{}' and time <= '{}'".format(yesterday_start, yesterday_end)
query_ops = client.operations.query
query_result = query_ops.execute(query)
# Extract the cost from the query result
cost = query_result.results[0]["cost"]["value"]
# Append the cost and subscription ID to the data list
data.append({'subscription_id': subscription_id, 'cost': cost})
Why not substitute the 'query_usage' method for the 'query' method to retrieve the Cost Usage data.
Note: The client.usage object returned by CostManagementClient has a query method that you can use to execute your query. The query method takes your query as a parameter and returns a QueryResponse object that you can use to extract the results.
Replace:
With: