我试图解析来自谷歌天气 api 的响应,但我得到这个格式不正确的错误,据我所知,响应格式正确。
以下是相关代码:
f = urllib.urlopen(WEATHERPATH + sys.argv[1])
parser = make_parser()
parser.setContentHandler(GoogleWeatherHandler())
parser.parse(f)
XML:
<?xml version="1.0"?>
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Ciudad Ju�rez, Chihuahua"/><postal_code data="Juarez"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2012-08-14"/>
<current_date_time data="2012-08-15 02:51:00 +0000"/>
<unit_system data="US"/></forecast_information>
<current_conditions>
<condition data="Cloudy"/>
<temp_f data="91"/>
<temp_c data="33"/>
<humidity data="Humidity: 22%"/>
<icon data="/ig/images/weather/cloudy.gif"/>
<wind_condition data="Wind: SE at 6 mph"/>
</current_conditions>
// similar markup
</weather>
</xml_api_reply>
和错误:
Traceback (most recent call last):
File "weather.py", line 34, in <module>
main()
File "weather.py", line 30, in main
parser.parse(f)
File "c:\Python26\lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "c:\Python26\lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
File "c:\Python26\lib\xml\sax\expatreader.py", line 211, in feed
self._err_handler.fatalError(exc)
File "c:\Python26\lib\xml\sax\handler.py", line 38, in fatalError
raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:179: not well-formed (invalid
token)
所有导入都已经到位,我相信解释器,但我在 xml 上找不到错误,第二:知道什么<unknown>:1:179
意思会很有效。
谢谢。