Python etching error when using sessions

In my django application, I created an advanced user profile using vars sessions. But when the registration form was saved and the user was about to create, I received the following error:

Traceback (most recent call last):

  File "\Python26\Lib\site-packages\django\core\servers\basehttp.py", line 279, in run
    self.result = application(self.environ, self.start_response)

  File "\Python26\Lib\site-packages\django\core\servers\basehttp.py", line 651, in __call__
    return self.application(environ, start_response)

  File "\Python26\Lib\site-packages\django\core\handlers\wsgi.py", line 245, in __call__
    response = middleware_method(request, response)

  File "\Python26\Lib\site-packages\django\contrib\sessions\middleware.py", line 36, in process_response
    request.session.save()

  File "\Python26\Lib\site-packages\django\contrib\sessions\backends\db.py", line 53, in save
    session_data = self.encode(self._get_session(no_load=must_create)),

  File "\Python26\Lib\site-packages\django\contrib\sessions\backends\base.py", line 88, in encode
    pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)

PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed

I was looking for an answer, but found nothing interesting. Any workarounds for this?

+3
source share
3 answers

It seems you have a cStringIO object in your session (maybe a downloaded file?), They cannot be pickled. Either write a special etching code, or make sure that all of your session data can be serialized.

+4
source

- , cStringIO.StringO, cStringIO.StringIO, I. - ?

+1

In support of Ivo's answer, a link is found here that can explain this: http://bugs.python.org/issue5345

This is not a typo. cStringIO.StringIO is a factory function that returns either a cStringO object (for writing) or cStringI (for reading). If this behavior is causing you a problem, then consider using StringIO.StringIO.

Alternatively, you can upgrade to Python 2.7 or 3.0 and use io.StringIO (), which does not have this limitation.

+1
source

All Articles