Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使烧杯会话在python瓶子框架中与gunicorn一起工作_Python_Bottle_Gunicorn_Beaker - Fatal编程技术网

尝试使烧杯会话在python瓶子框架中与gunicorn一起工作

尝试使烧杯会话在python瓶子框架中与gunicorn一起工作,python,bottle,gunicorn,beaker,Python,Bottle,Gunicorn,Beaker,我正在使用瓶子编写一个小型web程序,并将以下源文件命名为index.py。我还在程序中使用烧杯会话库。当我使用python index.py运行代码时,一切正常。但是当我使用gunicorn-c gunicorn.conf index:app时,我会收到这样的错误消息,说烧杯键bicker.session不存在。如何更改代码以使gunicorn服务器再次工作 Traceback (most recent call last): File "/Library/Python/2.7/site-

我正在使用瓶子编写一个小型web程序,并将以下源文件命名为
index.py
。我还在程序中使用烧杯会话库。当我使用
python index.py
运行代码时,一切正常。但是当我使用
gunicorn-c gunicorn.conf index:app
时,我会收到这样的错误消息,说烧杯键
bicker.session
不存在。如何更改代码以使gunicorn服务器再次工作

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/bottle-0.12.7-py2.7.egg/EGG-INFO/scripts/bottle.py", line 857, in _handle
    self.trigger_hook('before_request')
  File "/Library/Python/2.7/site-packages/bottle-0.12.7-py2.7.egg/EGG-INFO/scripts/bottle.py", line 640, in trigger_hook
    return [hook(*args, **kwargs) for hook in self._hooks[__name][:]]
  File "/Users/yizeng/Documents/python_projects/simple-courses/index.py", line 17, in setup_request
    request.session = request.environ['beaker.session']
KeyError: 'beaker.session'
index.py的源代码

import os, sys, bottle
from bottle import debug, route, request, run, Bottle, static_file, hook
from apps import model, views
from beaker.middleware import SessionMiddleware


app = bottle.app()

session_options = {
        'session.type': 'file',
        'session.cookie_expires': 300,
        'session.data_dir': './data',
        'session.auto': True
    }
@hook('before_request')
def setup_request():
    request.session = request.environ['beaker.session']

@app.route('/assets/<filepath:path>')
def server_static(filepath):
    return static_file(filepath, root='assets')

@app.route('/test')
def test():
    s = request.environ.get('beaker.session')
    s['test'] = s.get('test', 0) + 1
    s.save()
    return 'Test counter: %d' % s['test']

app_session = SessionMiddleware(app, session_options)
if __name__ == '__main__':
    app.run(app=app_session)
导入操作系统、系统、瓶子
从瓶子导入调试、路由、请求、运行、瓶子、静态文件、钩子
从应用程序导入模型、视图
从bicker.middleware导入SessionMiddleware
app=瓶子。app()
会话_选项={
'session.type':'file',
“session.cookie_过期”:300,
“session.data_dir”:“./data”,
“session.auto”:True
}
@hook('before_request')
def设置_请求():
request.session=request.environ['biker.session']
@app.route(“/assets/”)
def服务器_静态(文件路径):
返回静态文件(filepath,root='assets')
@应用程序路径(“/test”)
def test():
s=request.environ.get('beaker.session')
s['test']=s.get('test',0)+1
s、 保存()
返回“测试计数器:%d”%s[“测试”]
应用程序会话=会话中间件(应用程序、会话选项)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app.run(app=app\u会话)

我相信你根本不需要最后一块
,如果你的名字…
。Gunicorn将索引模块的应用程序“varibale”作为WSIG运行,这意味着它应该启动瓶子应用程序的一个实例