【问题标题】:Cherrypy 3.2 sessions broken, or am I doing it wrong?Cherrypy 3.2 会话中断,还是我做错了?
【发布时间】:2012-02-08 07:06:01
【问题描述】:

使用cherrypy 3.2 运行python 3,并且遇到了很多问题。首先,为了让 cookie 工作,我必须在 /etc/hosts 中伪造一个 fqdn。

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

在此之后,我尝试让会话工作,但我每次都获得一个新的会话 ID,并且在浏览器的任何位置的 cookie 中都没有设置 session_id 值。

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}}

有什么想法吗?

【问题讨论】:

  • “回答”按钮现在似乎无法点击。我通过反复试验弄清楚了这一点,希望这对其他人有所帮助。解决方案是为 tools.sessions.name 指定任何值,例如{'tools.sessions.name': 'hhh'} 在配置中。不知道为什么这不在文档中

标签: cherrypy


【解决方案1】:

我也遇到了同样的问题。我在cherrypy配置中添加了tools.sessions.name,现在它可以工作了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    相关资源
    最近更新 更多