2012-02-08 45 views
1

用cherrypy 3.2运行python 3,并且遇到了很多问题。首先,为了让cookies工作,我不得不在/ etc/hosts中伪造一个fqdn。Cherrypy 3.2会话中断,还是我做错了?

e.g. 
http://test:8080 [no cookies] 
http://test.local:8080 [cookies work] 

在此之后,我试图让会议的工作,但每次我得到一个新的会话ID,并没有SESSION_ID值被在Cookie在浏览器中的任何地方设置。

class HelloWorld: 
    @cherrypy.expose 
    def index(self, *args): 

    print("\n\n") 
    ### test cookies (works fine, no problems) 
    print(cherrypy.request.cookie) 
    cherrypy.response.cookie['c1'] = 'val1' 
    cherrypy.response.cookie['c1']['max-age'] = '3600' 

    cherrypy.response.cookie['d1'] = 'val2' 
    cherrypy.response.cookie['d1']['max-age'] = '3600' 

    ### test sessions (doesn't work) 

    print(cherrypy.session.load()) # always returns None 

    print(cherrypy.session.id) # different every refresh 

    print(cherrypy.session.get('foo')) # always returns None 
    cherrypy.session['foo'] = 'bar' 

    cherrypy.session.save() # apparently has no effect 

    return "Hello world!" 

任何人都可以提供一些建议或建议吗?我发现在Chrome中没有设置会话ID的Cookie,尽管我的其他值是。

我的配置是这样的:

'/': {'tools.sessions.on': True, 
     'tools.sessions.timeout': 7200}} 

任何想法?

+1

它看起来像“答案”按钮现在无法点击。我通过反复试验发现了这一点,希望这可以帮助别人。解决的办法是指定tools.sessions.name任何值,例如{ 'tools.sessions.name': 'HHH'}在配置。不知道为什么这不在文档中 – 2012-02-08 07:24:25

回答

2

我正面临同样的问题。我加tools.sessions.name到CherryPy的配置和现在的作品

相关问题