gpt4 book ai didi

python - Azure 费率卡 API 按货币筛选示例

转载 作者:行者123 更新时间:2023-12-03 05:44:54 25 4
gpt4 key购买 nike

我想根据资源的使用情况获取资源的价格,为此,我正在尝试azureratecard API。我正在使用 Azure 提供的 python SDK,这里是 azure 费率卡 API https://learn.microsoft.com/en-us/python/api/azure-mgmt-commerce/azure.mgmt.commerce.operations.ratecardoperations?view=azure-python 的链接

问题是,我们需要传递过滤器作为参数,但我不知道如何在过滤器中传递值。我知道我们可以使用报价 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'

最佳答案

我还没有尝试过,但查看了文档和 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'")

关于python - Azure 费率卡 API 按货币筛选示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55339317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com