首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图拉动零售天价

试图拉动零售天价
EN

Stack Overflow用户
提问于 2021-12-02 08:05:51
回答 1查看 118关注 0票数 0

我试图使用这个链接来拉动Azure零售价格,但是它给了我这个错误,请你指导我怎么做。

我不想在链接中应用任何过滤器。

代码语言:javascript
复制
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:

EN

回答 1

Stack Overflow用户

回答已采纳

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

错误是由于pyOpenSSL的版本,所以,尝试将版本更改为最新版本,

  • 卸载以前版本的pyOpenSSL

  • 安装pyOpenSSL-21.2.0的最新版本(最新版本).
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70195950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档