python代码求解怎么出错了

import httplib
try:
import json
except ImportError: # for Python 2.5
import simplejson as json

path = ('/maps/geo?q=207+N.+Defiance+St%2C+Archbold%2C+OH'
'&output=json&oe=utf8')
connection = httplib.HTTPConnection('maps.google.com')
connection.request('GET', path)
rawreply = connection.getresponse().read()
reply = json.loads(rawreply)
print reply['Placemark'][0]['Point']['coordinates'][:-1]
结果是
Traceback (most recent call last):
File "E:/Program Files (x86)/python2.7.3/来了", line 13, in <module>
print reply['Placemark'][0]['Point']['coordinates'][:-1]
KeyError: 'Placemark'

试试这个吧,那个api应该已经不用了

http://maps.googleapis.com/maps/api/geocode/json?address=207+N.+Defiance+St%2C+Archbold%2C+OH&oe=utf8&sensor=true

你可以参考

https://developers.google.com/maps/documentation/geocoding/

和 api v2 upgrade to v3

https://developers.google.com/maps/articles/geocodingupgrade

另外610的意思是

610 G_GEO_BAD_KEY
The given key is either invalid or does not match the domain for which it was given.追问

没懂额,要怎么操作啊?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-07
可能是少了一层。你dir(reply)一下看看。追问

怎样改啊

追答

梦未央说明了啊。问他吧。 目前你的响应里没有'Placemark'这个键 。所以程序走不下去。 可能是少了一步,也可能是没有认证。我自己没有试过。不能给你直接的答案。你再试试。

你在reply = json.loads(rawreply)的后面加一句
print dir(reply)
print reply
这样就知道你怎么去尝试了。

本回答被网友采纳
第2个回答  2013-06-07
reply 字典里没有Placemark
这个键 里边的结构是: {u'Status': {u'code': 610, u'request': u'geocode'}}追问

求教怎么改?

第3个回答  2013-06-07
reply
字典里没有Placemark
这个键
相似回答