尝试从 api.hostip.info 上传 xml 纬度、经度坐标。Python minidom 在本地 GAE(和 iPython)中运行良好,但在 Google GAE 中无法运行。我可以抛出下面的代码,但我认为我在从另一个网站提取 xml 时缺少特定于 Google GAE 的内容。
ip = self.request.remote_addr
IP_URL = "http://api.hostip.info/?="
def get_coords(ip):
url = IP_URL + ip
xml = None
try:
xml = urllib2.urlopen(url).read()
except urllib2.URLError, e:
return "in URLError "+ e.code
try:
if xml:
s = minidom.parseString(xml)
else:
return "unable to parse content"
except:
return "exception error unable to parse content"
try:
if s:
coords = s.getElementsByTagName("gml:coordinates")
else:
return "unable to get coords"
except:
return "exception error unable to get coords"
try:
if coords: #Google GAE fails on this if statement
p = coords[0].childNodes[0].nodeValue
else:
return "unable to get node value- points"
except:
return "exception unable to get node-value points"
try:
lon, lat = coords[0].childNodes[0].nodeValue.split(',')
points = [Point(lat,lon)]
return points
except:
return "unable to return points"
return None + "dropped to bottom"