【发布时间】: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