我想根据资源的使用情况获得价格,为此,我正在尝试azure ratecard API
。我正在使用Azure提供的python SDK,这是天蓝色价目表API https://docs.microsoft.com/en-us/python/api/azure-mgmt-commerce/azure.mgmt.commerce.operations.ratecardoperations?view=azure-python
问题是,我们需要将filter作为参数传递,但是我不知道如何在filter中传递值。我知道我们可以使用商品ID,货币,语言环境,区域作为过滤器,但是如何在价目表api中使用它们?
这就是我正在尝试的
from azure.mgmt.commerce import UsageManagementClient
ratecardclient = UsageManagementClient(credentials, subscription_id)
ratecard = ratecardclient.rate_card.get(filter=???)
我在过滤器中尝试过的内容
ratecard = ratecardclient.rate_card.get("OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")
ratecard = ratecardclient.rate_card.get(filter="OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")
我从上述过滤器中得到的错误
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'
答案 0 :(得分:1)
我还没有尝试过,但是查看文档和source code
时,我相信您需要指定OData过滤器字符串。请尝试使用类似过滤字符串的方法:
OfferDurableId eq '{OfferDurableId}' and Currency eq '{Currency}' and Locale eq '{Locale}' and RegionInfo eq '{RegionInfo}'
因此您的代码应为:
from azure.mgmt.commerce import UsageManagementClient
ratecardclient = UsageManagementClient(credentials, subscription_id)
ratecard = ratecardclient.rate_card.get(filter="OfferDurableId eq 'MS-AZR-0003p' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")
答案 1 :(得分:1)
从最根本的方面来看:
# 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'"
)