我试图使用这个链接来拉动Azure零售价格,但是它给了我这个错误,请你指导我怎么做。
我不想在链接中应用任何过滤器。
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)错误的ScreenShot:

发布于 2021-12-07 12:03:28

错误是由于pyOpenSSL的版本,所以,尝试将版本更改为最新版本,
pyOpenSSL和pyOpenSSL-21.2.0的最新版本(最新版本).https://stackoverflow.com/questions/70195950
复制相似问题