Chainguys 2021-08-19 02:07 采纳率: 93.6%
浏览 94
已结题

为什么print明明输出了,还报错?

import requests
from lxml import etree
from bs4 import BeautifulSoup
import time
import pandas as pd
import json
proxies = {
    'https': 'http://127.0.0.1:10818',
    'http': 'http://127.0.0.1:10818'
}

resp = requests.get("https://backend.tendermint.com/apps",proxies = proxies)
print(resp.status_code)

jdict = json.loads(resp.text)
total = []

for item in jdict["records"]:
    print(item['fields']["name"])
    name = item['fields']["name"]
    total.append(item['fields']["name"])

RT,打印正常,

Comic Chain
Dulce + Allies
Pylons
...
Unification WRK Oracle
WenChang
Zenchain

但是最后居然来一个报错

line 19, in <module>
    print(item['fields']["name"])
KeyError: 'name'

不是都全打出来了吗怎么还报错?什么鬼?

  • 写回答

4条回答 默认 最新

  • 小P聊技术 2021-08-19 09:44
    关注

    img

    最后的fields是个空的,你多加个判断就好了,代码没大问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 8月27日
  • 已采纳回答 8月19日
  • 创建了问题 8月19日