The error indicates that there is a self-signed cert that is not trusted in the chain. Given that the MS certs are all valid non-self signed certs I would suspect that your request is going through a local proxy or similar SSL intercept on your end and causing this issue. You would want to talk to your IT team.
Azure Retail price pull
Anurag singh kuhswaha
31
Reputation points
I am trying to pull API retail prices but i am getting this error :
import requests
import json
import pandas as pd
import os
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
# Call the Azure Retail Prices API
response = requests.get("https://prices.azure.com/api/retail/prices")
#response = http.request("GET", "https://example.com/", retries=Retry(10))
# Set your file location and filename to save your json and excel file
#filelocation = r'Folderpath'
filename = 'azureretailprices_vm_scus'
# Create an array to store price list
priceitems= []
#Add the retail prices returned in the API response to a list
for i in response.json()['Items']:
priceitems.append(i)
print(response.json()["NextPageLink"])
# Retrieve price list from all available pages until there is no 'NextPageLink' available to retrieve prices
# Retrieve price list from all available pages until there is a 'NextPageLink' available to retrieve prices
while response.json()["NextPageLink"] != None:
for i in response.json()['Items']:
priceitems.append(i)
response = requests.get(response.json()["NextPageLink"])
print(response.json()["NextPageLink"])
# Retrieve price list from the last page when there is no "NextPageLink" available to retrieve prices
if response.json()["NextPageLink"] == None:
for i in response.json()['Items']:
priceitems.append(i)
# Write the price list to a json file
with open(os.path.join('folder',filename) + '.json', 'w') as f:
json.dump(priceitems, f)
# Open the price list json file and load into a variable
with open(os.path.join('folder',filename) + '.json', encoding='utf-8') as f:
raw = json.loads(f.read())
# Convert the price list into a data frame
df = pd.json_normalize(raw)
# Save the data frame as an excel file
df.to_excel(os.path.join('folder',filename) + '.xlsx', sheet_name='RetailPrices', index=False)