我正在localhost上开发一个cherrypy应用程序,并编写本文来了解sessions的情况。在
import cherrypy
class WhyNotSessions(object):
@cherrypy.expose
def index(self):
if 'count' not in cherrypy.session:
cherrypy.session['count'] = 0
cherrypy.session['count'] += 1
return "Session count is %s" % cherrypy.session.get('count')
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.sessions.secure': True
}
}
cherrypy.quickstart(WhyNotSessions(), '/', conf)
这和预期的一样,只要我从conf
中注释出'tools.sessions.secure': True
,重载时count
递增。我想更好地了解这里发生了什么,因为我打算在生产中使用安全会话。在
我刚刚也遇到了同样的问题。在
这是因为工具.会话.安全'to True将“secure”标志添加到生成的存储会话id的cookie中
如果您没有在CherryPy中使用HTTPS,那么在以后的任何请求中都不会返回这个cookie,因此每次都会生成一个新的会话id。在
在CherryPy中启用HTTPS解决了这个问题。请参见CherryPy documentation on SSL了解如何打开此功能。在
相关问题 更多 >
编程相关推荐