【发布时间】:2019-06-11 03:47:55
【问题描述】:
在 Python(使用 Flask)中使用 JSON 库时出现 KeyError 不是很懂。
KeyError: 'sites'
是我遇到的错误
JSON 代码:
{
"sites": {
"example-site": {
"domains": [
"example.pagehost.com",
"127.0.0.1:5000"
],
"pages": {
"index/": "index.html"
},
"index": "index.html",
"owner": "Bevan",
"id": "example-site"
}
}
}
Python 代码:
global sites_json
fsite = ""
print("Finding site")
for site in sites_json['sites']:
for domain in site['domains']:
if domain == host:
fsite = site
print("Found site")
break
侵权行似乎是 for site in sites_json['sites'] 请知道发生了什么的人帮忙吗?
【问题讨论】:
-
请显示
sites_json的类型:print(type(sites_json))