我正在尝试用Python解析XML,我使用的是yandex-maps https://pypi.python.org/pypi/yandex-maps包,但并没有走得太远。
>>> from yandex_maps import api
>>> api_key = 'my_api_key'
>>> pos = api.geocode(api_key, u'Санкт-Петербург, Бумажная 4')我收到错误:
File "./1.py", line 6, in <module>
pos = api.geocode(api_key, u'Санкт-Петербург,Бумажная 4')
File "/usr/local/lib/python2.7/dist-packages/yandex_maps/api.py", line 49, in geocode
return _get_coords(xml)
File "/usr/local/lib/python2.7/dist-packages/yandex_maps/api.py", line 66, in _get_coords
dom = xml.dom.minidom.parseString(response)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 1928, in parseString
return expatbuilder.parseString(string)
File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
return builder.parseString(string)
File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
parser.Parse(string, True)
xml.parsers.expat.ExpatError: mismatched tag: line 6, column 2发布于 2016-02-04 16:38:52
我也有同样的问题,当你使用这个库(api.py第13行:"GEOCODE_URL = 'http://geocode-maps.yandex.ru/1.x/?'")时,Yandex返回你301到https协议。因此,只需找到另一个库,或重写URL :)
此外,您还可以应用此修复:https://bitbucket.org/kmike/yandex-maps/pull-requests/2/fix-301-from-http-to-https/diff
https://stackoverflow.com/questions/35179672
复制相似问题