使用会话时发生Python酸洗错误 [英] Python pickling error when using sessions

查看:90
本文介绍了使用会话时发生Python酸洗错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的django应用中,我正在使用会话变量创建扩展的用户配置文件.但是,当保存了注册表并要创建用户时,出现以下错误:

In my django app I was creating an extended user profile using session vars. But when registration form was saved and user was about to create, I got 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

我已经用Google搜索了答案,但没有发现任何有趣的东西.有任何解决方法吗?

I've googled for an answer, but found nothing interesting. Any workarounds for this ?

推荐答案

似乎您的会话中有一个cStringIO对象(也许是一个上载的文件?),无法腌制这些对象.编写自定义的腌制代码,或者确保所有会话数据都可以序列化.

It appears you have a cStringIO object in your session (perhaps an uploaded file?), these cannot be pickled. Either write custom pickling code or make sure all your session data can be serialized.

这篇关于使用会话时发生Python酸洗错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆