python 2.7 urllib2.Request 按键错误
python 2.7 urllib2.Request KeyError
我已成功填写 json.load(response) 请求并能够 navigate/see 结果,这似乎是我所期待的。但是,当我尝试访问属性时遇到 KeyError。在这种情况下,我需要将局部变量设置为 "SHORT_NAME" 属性。
{u'fieldAliases': {u'SHORT_NAME': u'SHORT_NAME', u'OBJECTID':
u'OBJECTID'}, u'fields': [{u'alias': u'OBJECTID', u'type':
u'esriFieldTypeOID', u'name': u'OBJECTID'}, {u'alias': u'SHORT_NAME',
u'length': 50, u'type': u'esriFieldTypeString', u'name':
u'SHORT_NAME'}], u'displayFieldName': u'LONG_NAME', u'features':
[{u'attributes': {u'SHORT_NAME': u'Jensen Beach to Jupiter Inlet',
u'OBJECTID': 17}}]}
我的 python 访问上面的代码:
reqAp = urllib2.Request(queryURLAp, paramsAp)
responseAp = urllib2.urlopen(reqAp)
jsonResultAp = json.load(responseAp) #all good here! above example is what this contains
#trying to set variable to the SHORT_NAME attribute
for featureAp in jsonResultAp['features']:
aqp = feature['attributes']['SHORT_NAME']
#this fails with: "KeyError: 'SHORT_NAME'"
很明显 "SHORT_NAME" 在那里,所以我不太确定我做错了什么。
感谢任何反馈!
变化:
aqp = feature['attributes']['SHORT_NAME']
收件人:
aqp = featureAp['attributes']['SHORT_NAME']
我已成功填写 json.load(response) 请求并能够 navigate/see 结果,这似乎是我所期待的。但是,当我尝试访问属性时遇到 KeyError。在这种情况下,我需要将局部变量设置为 "SHORT_NAME" 属性。
{u'fieldAliases': {u'SHORT_NAME': u'SHORT_NAME', u'OBJECTID': u'OBJECTID'}, u'fields': [{u'alias': u'OBJECTID', u'type': u'esriFieldTypeOID', u'name': u'OBJECTID'}, {u'alias': u'SHORT_NAME', u'length': 50, u'type': u'esriFieldTypeString', u'name': u'SHORT_NAME'}], u'displayFieldName': u'LONG_NAME', u'features': [{u'attributes': {u'SHORT_NAME': u'Jensen Beach to Jupiter Inlet', u'OBJECTID': 17}}]}
我的 python 访问上面的代码:
reqAp = urllib2.Request(queryURLAp, paramsAp)
responseAp = urllib2.urlopen(reqAp)
jsonResultAp = json.load(responseAp) #all good here! above example is what this contains
#trying to set variable to the SHORT_NAME attribute
for featureAp in jsonResultAp['features']:
aqp = feature['attributes']['SHORT_NAME']
#this fails with: "KeyError: 'SHORT_NAME'"
很明显 "SHORT_NAME" 在那里,所以我不太确定我做错了什么。
感谢任何反馈!
变化:
aqp = feature['attributes']['SHORT_NAME']
收件人:
aqp = featureAp['attributes']['SHORT_NAME']