简体   繁体   English

AppEngine 混乱 - CGI,WSGI 兼容?

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

I'm confused.我很困惑。

If AppEngine is supposed to allow running of WSGI-employing apps..如果 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)

.. then why does env not contain variables that PEP 333 lists as must -be-present -- causing the wsgiref.util.request_uri() to raise a KeyError ? .. 那么为什么env不包含PEP 333列出的必须存在的变量 - 导致wsgiref.util.request_uri()引发KeyError

I'm basically writing some libraries that will need to work either AppEngine or a typical Apache + modwsgi setup.我基本上是在编写一些需要在 AppEngine 或典型的 Apache + modwsgi 设置中工作的库。 I thought it would be enough to simply write a WSGI compliant app, but seems AppEngine itself.. is not?我认为只需编写一个符合WSGI的应用程序就足够了,但似乎 AppEngine 本身..不是吗?

the environ which must contain wsgi specific keys is the environ passed to the wsgi application callable.必须包含environ特定键的环境是传递给 wsgi 应用程序可调用的环境。 PEP-333 does not require that this be the value os.environ . PEP-333 不要求这是os.environ的值。 CGI applications will find that many of the keys will be in os.environ , because the gateway server has provided them, and the cgi to wsgi gateway interface (say, wsgiref.handlers.CGIHandler ,) need add only the wsgi specific keys before calling the wsgi application. CGI 应用程序会发现很多键都在os.environ中,因为网关服务器已经提供了它们,而 cgi 到 wsgi 网关接口(比如wsgiref.handlers.CGIHandler )只需要在调用之前添加 wsgi 特定的键wsgi 应用程序。

To be clear, when PEP-333 mentions environ , it does not mean os.environ .需要明确的是,当 PEP-333 提到environ时,它并不意味着os.environ

EDIT: google.appengine.ext.webapp.Request apparently inherits from webob.Request .编辑: google.appengine.ext.webapp.Request显然继承自webob.Request Thus, a webapp handler can access the wsgi environ something like so.因此,webapp 处理程序可以像这样访问 wsgi environ

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

AFAIK pep 333 says nothing about forcing all of the wsgi environ variables into os.environ unless emulating CGI, only that the wsgi environ variable should contain these things. AFAIK pep 333 没有说明强制所有 wsgi 环境变量进入os.environ除非模拟 CGI,只是 wsgi 环境变量应该包含这些东西。

Within the context of a wsgi application the environ dictionary is the part that is passed to your wsgi application function.在 wsgi 应用程序的上下文中,环境字典是传递给 wsgi 应用程序 function 的部分。 In GAE you can access the wsgi environ dict via request.environ .在 GAE 中,您可以通过request.environ访问 wsgi environ dict。 So I think your code should be more like:所以我认为你的代码应该更像:

# 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