0
IM与Infoblox的API接口时,类型错误:字符串索引必须是整数,不能海峡,试图创建一个字典
这里是数据的模样..
[
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMTAwLjIyOC4wLzI0LzA:10.100.228.0/24/default",
"comment": "jacksonville - mgmt",
"network": "10.100.228.0/24",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMTAwLjIxLjAvMjQvMA:10.100.21.0/24/default",
"comment": "miami - mgmt",
"network": "10.100.21.0/24",
"network_view": "default"
}]
这里是我的代码
def foo():
r = session.get(url + 'network', params={'_max_results': str(5000)})
z = r.json()
return dict((h['comment'], h['network']) for h in r.content)
#return r.content
即时得到错误“类型错误:字符串索引必须是整数,而不是STR”执行上述功能时。
现在即时得到一个KeyError异常:“注释”,可以在字典中做出以上?或者每个网络应该是一本字典? – wwi
@wwi:那么你的数据不是你发布的。 – Daniel