问题描述
我使用App Engine python来托管应用程序,并且喜欢使用Appstats和其他一些以中间件运行的库。但是,当我通过appengine_config.py设置中间件时(如下所示),它可以在dev服务器上工作,但不在生产中。 Appstats和gaesessions在开发服务器中像一个魅力一样工作,在生产中完全不工作。这里是我的appengine_config.py,位于我的根目录/ src目录中:
来自com.impactpy.gaesessions import SessionMiddleware
COOKIE_KEY ='nice try'
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats导入记录
app = SessionMiddleware(app,cookie_key = COOKIE_KEY)
app = recording.appstats_wsgi_middleware(app)
return app
有什么想法?
更新
所以我将这个备份起来,因为我再次尝试修复它无济于事。我将appengine_config.py烧录到:
from google.appengine.ext.appstats导入记录
def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app
和app.yaml包含
内置函数:
- datastore_admin:在
- remote_api :on
- appstats:on
我的应用使用基本的webapp,处理文件包括:
pre $应用程序= webapp.WSGIApplication([
('/ handler',myHandlerClass)
),debug = True)
def main():
run_wsgi_app(应用程序)
$ b $如果__name__ ==__main__:
main )
部署工作正常。应用程序已经持续了一年,并且看到了很多请求。 myapp.appspot.com/_ah/stats出现了一个刷新按钮,没有数据,并显示消息没有请求已被记录等等我很困惑!
我认为问题在于如何导入SessionMiddleware。尝试将gaesessions放在项目目录的顶层。
以下是我成功使用的 appengine_config.py
:来自gaesessions的
从google.appengine.ext.appstats导入SessionMiddleware
导入记录
def webapp_add_wsgi_middleware(app):
app = SessionMiddleware(app,cookie_key =s3cr3t)
app = recording.appstats_wsgi_middleware(app)
返回应用程序
I'm using App Engine python to host an application and would love to use Appstats and a couple of other libraries that run as middleware. However, when I set up middleware through appengine_config.py (as shown below) it works on the dev server but not in production. Appstats AND gaesessions work like a charm in the dev server and don't work at all in production. Here is my appengine_config.py, located in my root /src dir:
from com.impactpy.gaesessions import SessionMiddleware
COOKIE_KEY = 'nice try'
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
app = SessionMiddleware(app, cookie_key=COOKIE_KEY)
app = recording.appstats_wsgi_middleware(app)
return app
Any ideas?
UPDATE
So I'm bringing this back up as I've tried again to fix it to no avail. I've boiled appengine_config.py down to:
from google.appengine.ext.appstats import recording
def webapp_add_wsgi_middleware(app):
app = recording.appstats_wsgi_middleware(app)
return app
and app.yaml includes
builtins:
- datastore_admin: on
- remote_api: on
- appstats: on
My app uses basic webapp, bottom of every request-handling file includes:
application = webapp.WSGIApplication( [
('/handler', myHandlerClass)
],debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Deploying works fine. App has been going strong for over a year and sees lots of requests. myapp.appspot.com/_ah/stats comes up showing the GUI with a refresh button, no data, and the message "No requests have been recorded yet" etc. I'm confused!
I think the problem is how you import SessionMiddleware. Try to put gaesessions at the top level of your project directory.
Here is an appengine_config.py
I used successfully:
from gaesessions import SessionMiddleware
from google.appengine.ext.appstats import recording
def webapp_add_wsgi_middleware(app):
app = SessionMiddleware(app, cookie_key="s3cr3t")
app = recording.appstats_wsgi_middleware(app)
return app
这篇关于App Engine(python)在生产环境中跳过了webapp中间件(如Appstats),但在dev服务器上工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!