Azure ratecard api按货币examp筛选

2024-09-27 21:22:39 发布

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

我想根据资源的使用情况得到它的价格,为此,我尝试azure ratecard API。我使用的是Azure提供的python sdk,这里是Azure ratecard api的链接https://docs.microsoft.com/en-us/python/api/azure-mgmt-commerce/azure.mgmt.commerce.operations.ratecardoperations?view=azure-python

问题是,我们需要将filter作为参数传递,但我不知道如何在filter中传递值。我知道我们可以使用offer id、currency、locale、region作为过滤器,但是如何在ratecardapi中使用它们呢?

这就是我要做的

from azure.mgmt.commerce import UsageManagementClient

ratecardclient = UsageManagementClient(credentials, subscription_id)
ratecard = ratecardclient.rate_card.get(filter=???)

我试过的过滤器

^{pr2}$

我从上面的过滤器得到的错误

Traceback (most recent call last):
  File "C:/Users/gsc/PycharmProjects/GsGit_Azure_cot/Azure/ADALAuth.py", line 375, in <module>
    ratecard = ratecardclient.rate_card.get("OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")
  File "C:\Users\gsc-30310\PycharmProjects\env_python3.6.8_v1\lib\site-packages\azure\mgmt\commerce\operations\rate_card_operations.py", line 94, in get
    raise models.ErrorResponseException(self._deserialize, response)
azure.mgmt.commerce.models.error_response.ErrorResponseException: Operation returned an invalid status code 'Bad Request'

Tags: andapi过滤器getratecardfilterazure
2条回答

来自Unitest:

    # OfferDurableID: https://azure.microsoft.com/en-us/support/legal/offer-details/
    rate = self.commerce_client.rate_card.get(
        "OfferDurableId eq 'MS-AZR-0062P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"
    )

https://github.com/Azure/azure-sdk-for-python/blob/master/azure-mgmt-commerce/tests/test_mgmt_commerce.py

我没有尝试过,但是看看文档和^{},我相信您需要指定OData筛选器字符串。请尝试类似于筛选器字符串的内容:

OfferDurableId eq '{OfferDurableId}' and Currency eq '{Currency}' and Locale eq '{Locale}' and RegionInfo eq '{RegionInfo}'

所以你的代码应该是:

^{pr2}$

相关问题 更多 >

    热门问题