API调用失败

时间:2020-05-17 15:26:47

标签: json api

我编写了一个脚本来对https://opendata.aemet.es/AEMET_OpenData_specification.json进行API调用,但无法恢复json文件中键“ paths”下的数据。我已经编写了以下代码,但出现“ TypeError:字符串索引必须为整数”错误。 有谁能够帮助我? 谢谢

import requests
import json

url='https://opendata.aemet.es/AEMET_OpenData_specification.json'
r=requests.get(url)
print(f'Status code: {r.status_code}')

response_dict=r.json()
archivo_legible='datos_aemet_legibles.json'
with open (archivo_legible, 'w') as f:
    json.dump(response_dict, f, indent=4)

print(f'Keys del diccionario: {response_dict.keys()}\n')

respuesta=response_dict['paths']

for ruta in respuesta:
    print(ruta['get']['summary'])

0 个答案:

没有答案
相关问题