2012-02-29 61 views
3

當提供請求時,GAE會自動插入響應標頭X-AppEngine-Country,該值設置爲指示發出請求的國家/地區的值。但是,在GAE發佈響應之前,我希望能夠在我的一個片段中使用此值。是否可以在應用程序中使用X-AppEngine-Country

我寫了這個代碼:

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' 

是否有使用的應用程序中這個數值的任何方式?

+0

你爲什麼認爲應答應該有國家代碼?爲什麼你需要在回覆中有國家代碼? \ – 2012-02-29 14:31:27

+0

@ShayErlichmen我認爲你錯過了這一點。響應具有國家代碼,因爲Google App Engine會插入它。 [更多這裏](http://www.rominirani.com/2011/07/11/x-appengine-country-http-header-google-app-engine/) – qdii 2012-02-29 14:37:20

+0

休息是什麼去OUT請求是什麼來IN ,我認爲你混淆了迴應和要求 – 2012-02-29 14:48:44

回答

相關問題