簡體   English   中英

AppEngine 混亂 - CGI,WSGI 兼容?

[英]AppEngine confusion - CGI, WSGI-compliant?

我很困惑。

如果 AppEngine 應該允許運行使用 WSGI 的應用程序..

# somewhere in a webapp.RequestHandler
env = dict(os.environ.items())
for key, value in env.items():
    self.response.out.write(key+': '+value+'<br/>')

req_uri = wsgiref.util.request_uri(env)

.. 那么為什么env不包含PEP 333列出的必須存在的變量 - 導致wsgiref.util.request_uri()引發KeyError

我基本上是在編寫一些需要在 AppEngine 或典型的 Apache + modwsgi 設置中工作的庫。 我認為只需編寫一個符合WSGI的應用程序就足夠了,但似乎 AppEngine 本身..不是嗎?

必須包含environ特定鍵的環境是傳遞給 wsgi 應用程序可調用的環境。 PEP-333 不要求這是os.environ的值。 CGI 應用程序會發現很多鍵都在os.environ中,因為網關服務器已經提供了它們,而 cgi 到 wsgi 網關接口(比如wsgiref.handlers.CGIHandler )只需要在調用之前添加 wsgi 特定的鍵wsgi 應用程序。

需要明確的是,當 PEP-333 提到environ時,它並不意味着os.environ

編輯: google.appengine.ext.webapp.Request顯然繼承自webob.Request 因此,webapp 處理程序可以像這樣訪問 wsgi environ

class MainPage(webapp.RequestHandler):
    def get(self):
        dosomethingwith(self.request.environ)

AFAIK pep 333 沒有說明強制所有 wsgi 環境變量進入os.environ除非模擬 CGI,只是 wsgi 環境變量應該包含這些東西。

在 wsgi 應用程序的上下文中,環境字典是傳遞給 wsgi 應用程序 function 的部分。 在 GAE 中,您可以通過request.environ訪問 wsgi environ dict。 所以我認為你的代碼應該更像:

# somewhere in a webapp.RequestHandler
env = self.request.environ
for key, value in env.iteritems():
    self.response.out.write(key+': '+value+'<br/>')
req_uri = wsgiref.util.request_uri(env)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM