【发布时间】:2012-02-29 14:08:56
【问题描述】:
在处理请求时,GAE 会自动插入响应标头 X-AppEngine-Country,并设置为指示发出请求的国家/地区的值。但是,在 GAE 发出响应之前,我希望能够在我的 sn-p 中使用这个值。
我写了这段代码:
class TestPage(webapp2.RequestHandler):
def get(self):
country = self.response.headers["X-AppEngine-Country"]
self.response.out.write("<pre>country %s </pre>" % country)
但是打开页面会导致崩溃:
File "/base/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/headers.py", line 16, in __getitem__
raise KeyError(key)
KeyError: 'x-appengine-country'
有没有办法在应用程序中使用这个值?
【问题讨论】:
-
为什么你认为响应应该有国家代码?为什么您需要在响应中包含国家/地区代码? \
-
@ShayErlichmen 我认为你没有抓住重点。响应具有国家/地区代码,因为 Google App Engine 插入了它。 more here
-
repose 是输出请求是输入,我认为你混淆了响应和请求
标签: python google-app-engine geolocation