简体   繁体   中英

Error using CherryPy Tools session

I have a python project which uses the CherryPy library. I run the project from Eclipse. On one virtual machine the code runs ok, but on another virtual machine, exactly the same code gives me an error in the line:

cherrypy.tools.sessions.on = True

The error itself is:

File "/usr/local/lib/python2.6/dist-packages/cherrypy/_cptools.py", line 68, in _set_on
    raise AttributeError(_attr_error)
AttributeError: CherryPy Tools cannot be turned on directly. Instead, turn them on via config, or use them as decorators on your page handlers.
*** glibc detected *** /usr/bin/python2.6: munmap_chunk(): invalid pointer: 0x0000000002aacee9 ***

and a backtrace follows. Since the code runs without an error on the other machine, I assume it is some config problem, but I couldn't locate it.

EDIT I don't know if it is relevant to my problem, but I've noticed that the CherryPy version on the machine where the code runs ok is 3.1.2, while on the machine where I get the error it is 3.2.2

EDIT 2 I am not a python programmer, I was forced (by circumstances) to inherit the code from the server guy who left the company. So sorry if my question is very (very) basic. These settings are present both in the code and in a configuration file, and that way it works OK with the 3.1.2 version. I just want to be sure it is safe to delete from the code the lines that causes the error, when using the 3.2.2 version.

The error message is telling you your line of code isn't valid. Depending on the context in which you want to turn on sessions, move it to config.update:

cherrypy.config.update({"tools.sessions.on": True})

...or a config file:

[/path]
tools.sessions.on = True

...or a _cp_config attribute:

class Root:
    _cp_config = {"tools.sessions.on": True}

See http://docs.cherrypy.org/dev/refman/_cpconfig.html#declaration for more on configuration declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM