Cherrypy会话不适用于所有域

时间:2018-07-23 14:07:13

标签: python-3.x session cherrypy

我遇到了cherrypy.session的问题,它在localhost上非常有效,但在127.0.0.1上却无效。同样在Heroku中,当我设置FileSession时,它会在找不到会话文件的所有页面上返回错误。否则,会话只能在*.herokuapp.com上工作,而不能在任何第二级域上工作。如何解决呢? Google很少有关于Cherrypy会话的信息

server.py

cherrypy.log.access_log.propagate = False
conf={
    'global': 
    {
        'server.socket_host': "0.0.0.0",
        'server.socket_port': int(os.environ.get('PORT', settings.WEBPORT)),
        'server.thread_pool': 10
    },
    '/': 
    {

        'tools.sessions.on': True,
        'tools.sessions.timeout': 1440,
        'tools.sessions.storage_class': cherrypy.lib.sessions.FileSession,
        'tools.sessions.storage_path': os.path.join(os.path.dirname(os.path.abspath(__file__)),".sessions"),
    },
    "/static":
    {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': os.path.join(os.path.dirname(os.path.abspath(__file__)),"static")
    }
}
cherrypy.quickstart(web.Server(),"/",conf)

web.py

class Server(object):

    @cherrypy.expose
    def index(self,*args,**kwargs):
        lang=kwargs.get("lang")
        kwargs.pop("lang",None)
        if not "lang" in cherrypy.session:
            if lang in ["ru","en"]:
                cherrypy.session["lang"]=lang
            else:
                cherrypy.session["lang"]="en"
        elif lang in ["ru","en"]:
            cherrypy.session["lang"]=lang
        lang=cherrypy.session.get("lang")

        # templating page there with the 'lang'
        p=webProcessor.Task(lang)
        return p.index()

0 个答案:

没有答案