401尝试时出错https://azure.microsoft.com/enus/resources/samples/billingpythonratecardapi

2024-09-27 21:25:49 发布

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

'' 尝试遵循https://azure.microsoft.com/en-us/resources/samples/billing-python-ratecard-api/示例,但获取keyError'location'。你知道吗

试着打印出答案,是401。 我也可以访问这个页面:https://manage.windowsazure.com/。onmicrosoft.com#工作区/AdminTasks/SubscriptionMapping 我确实看到了我订阅页面的列表。你知道吗

我不确定token=bearerToken应该是什么

''

#(base) C0233333:Python-RateCard-Sample eeeeeee$ cat ratecardsample.py

使用这个HTTP库包

导入请求

# Parameters need for API
# subscription, token and offer ID has been modifyed 
# I am very sure I have my correct values except I am not sure how to find the token value
subscription = '99999999-bbbb-4ecc-9999-dd9999999999'
token = '<bearerToken>'
offer = 'MS-AZR-0019Z'
currency = 'USD'
locale = 'en-US'
region = 'US'
rateCardUrl = 

https://management.azure.com:443/subscriptions/{subscriptionId}/providers”/Microsoft.Commerce/RateCard?api version=2016-08-31-preview&;filter=OfferDurableId eq{offerId}和Currency eq{currencyId}和Locale eq{localeId}和RegionInfo eq{regionId}'。格式(subscriptionId=subscription,offerId=offer,currencyId=Currency,localeId=Locale,regionId=region) 打印(rateCardUrl) #不允许重定向并调用RateCard API 响应=请求。获取(rateCardUrl,allow\u redirects=False,headers={'Authorization':'Bearer%s'%token}) 打印(响应)

# Look at response headers to get the redirect URL
redirectUrl = response.headers['Location']

# Get the ratecard content by making another call to go the redirect URL
rateCard = requests.get(redirectUrl)

# Print the ratecard content
print(rateCard.content) 

Tags: thetohttpscomtokencontentazuresubscription

热门问题