我在 Google App Engine 中有一个 python 应用程序,当我尝试获取 XML 提要时,没有任何反应,除了在 AppEngineLauncher 的日志控制台中,我得到
WARNING 2013-03-21 23:37:39,482 urlfetch_stub.py:453] Stripped prohibited headers from URLFetch request: ['Host']
这是我的代码:
class FindStops(webapp2.RequestHandler):
def post(self):
bound=self.request.POST["bound"]
line=self.request.POST["stop"]
stops=urllib2.urlopen("http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=sf-muni&r=" + line)
tree=ET.parse(stops)
root=tree.getroot()
title=list()
for info in tree.findall('stop'):
title.append(info.get('title'))
for name in title:
self.response.out.write(name)
这是 XML 的样子:
<body copyright="All data copyright San Francisco Muni 2013.">
<route tag="F" title="F-Market & Wharves" color="555555" oppositeColor="ffffff" latMin="37.7625199" latMax="37.8085899" lonMin="-122.43487" lonMax="-122.39345">
<stop tag="5184" title="Jones St & Beach St" lat="37.8072499" lon="-122.41737" stopId="15184"/>
<stop tag="3092" title="Beach St & Mason St" lat="37.80741" lon="-122.4141199" stopId="13092"/>
<stop tag="3095" title="Beach St & Stockton St" lat="37.8078399" lon="-122.41081" stopId="13095"/>
.
.
.
我很确定我正在正确解析 XML,但是 self.response.out.write 什么也没打印出来,所以我在这里不知所措。