python - Can't pickle <type 'function'>: attribute lookup __builtin__.function failed -


i'm receiving error in django application, however, happens once day or less , it's proving extremely difficult debug.

environment:  request method: post  django version: 1.3.1 python version: 2.6.6 installed applications: ['django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.sites',  'fimedlabs',  'data',  'djcelery'] installed middleware: ('django.middleware.common.commonmiddleware',  'django.contrib.sessions.middleware.sessionmiddleware',  'fimedlabs.auth.usermiddleware')   traceback: file "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response   178.                 response = middleware_method(request, response) file "/usr/local/lib/python2.6/dist-packages/django/contrib/sessions/middleware.py" in process_response   36.                 request.session.save() file "/usr/local/lib/python2.6/dist-packages/django/contrib/sessions/backends/db.py" in save   57.             session_data = self.encode(self._get_session(no_load=must_create)), file "/usr/local/lib/python2.6/dist-packages/django/contrib/sessions/backends/base.py" in encode   93.         pickled = pickle.dumps(session_dict, pickle.highest_protocol)  exception type: picklingerror @ / exception value: can't pickle <type 'function'>: attribute lookup __builtin__.function failed 

i've tried answer this:

how tell object attribute pickle fails?

by adding self actual error see if print in django error no avail.

where can print out object giving issues error appear in django error page?

thanks! ~matt

edit: object i'm storing in cache, user object code:

class user(object): username = str() userid = uuid.uuid(int=0)  client = models.client() clientid = uuid.uuid(int=0) clientname = ''  data = models.user() accesslevel = models.accesslevel()  active = false client_active = false isfimed = false isfimedadmin = false isclientadmin = false isfimedmanager = false mysettingsform = none viewingas = false  menu = []  _exists = false _authenticated = false  def __str__(self):     return str(self.__dict__.copy())  def __getstate__(self):     return self.__dict__.copy()  def __setstate__(self, dict):     self.__dict__ = dict  def __init__(self, username=none):     if username:         self.initialize(username)  def initialize(self, username):     self.username = username     model = models.user.objects.filter(username=username).all()     if len(model) == 1:         model = model[0]         self.data = model         self._exists = true         self.userid = self.data.id         self.active = self.data.active         self.isfimed = self.data.isfimed()         self.isfimedadmin = self.data.isfimedadmin()         self.isclientadmin = self.data.isclientadmin()         self.isfimedmanager = self.data.isfimedmanager()         self.mysettingsform = userformself(initial={"id":model.id, "username":model.username, "name":model.name, "email":model.email, "phone":model.phone})          self.accesslevel = models.accesslevel.objects.filter(id=self.data.accesslevel_id)[:1][0].level         cli = self.data.client         self.client = cli         self.clientid = cli.id         self.clientname = cli.name         if cli.active:             self.client_active = true          model.lastlogin = datetime.datetime.now()         model.save()          self.menu = getmenu(self.data)     else:         self._exists = false  def authenticate(self, password):     self._authenticated = false     if (self.active == false or self.client_active == false):         return false     if self._exists:         import hashlib         hash = hashlib.md5('%s%s' % (str(password), self.data.pwsalt)).hexdigest()         if hash == self.data.pwhash:             self._authenticated = true             return true     return false  def updateuser(self):     self.initialize(models.user.objects.filter(id=self.userid).get().username)  def mkcontext(self):     c = context()     c['menu'] = self.menu     c['user'] = self     c['language'] = language     c['colors'] = colors     c["isfimed"] = self.isfimed     c["isfimedadmin"] = self.isfimedadmin     c["isclientadmin"] = self.isclientadmin     c["isfimedmanager"] = self.isfimedmanager     c["mysettingsform"] = self.mysettingsform     return c 

edit: wsgi file after werkzeug:

import django.core.handlers.wsgi djangoapplication = django.core.handlers.wsgi.wsgihandler() def application(environ, start_response):     if 'script_name' in environ:         del environ['script_name']     return djangoapplication(environ, start_response) # following lines enable werkzeug debugger import django.views.debug def null_technical_500_response(request, exc_type, exc_value, tb):     raise exc_type, exc_value, tb django.views.debug.technical_500_response = null_technical_500_response werkzeug.debug import debuggedapplication application = debuggedapplication(application, evalex=true) 

where can print out object giving issues error appear in django error page?

the short answer - without recompiling cpickle, can't.

longer answer: piece of code raises exception:

root $ grep -hra "attribute lookup" /usr/lib64/ 2>/dev/null | grep -a failed /usr/lib64/python2.7/lib-dynload/cpickle.so:h�h���p0h�5zm h�=1��m��h��h�zm �����h�=�1�h���m��h��h��m �����h�4m h�5~h���h���������h�m h�5th���h���������h��l h�5�h���qh�����d���h�m h�5nh���sh�����f���h�dm h�5bh���5h�����(���h�=x1��o��h�hc h�5i h�=u1�a��h��l �vh��h��i�������h���rk��h�=.h����j��h�5$h��h��h�d$�g��h�d$h��th�h��h��h��gh�dl�tth�qh�5nh�=kh��1��xk��h�5bh��h��i����f��h�5\l��h���f��h��th�eh��h��h�e��m�������i�$h��h��i�$�t���i�dl���p0�d���f�h�eh��h��h�e�f���h�h���p0�7���@h�|$h��p0�����h�h���p0�����h�h���p0�k�����uh��sh�h�h: h���th�;: h���h�h���u�h�[��h��m��h��attribute deletion not supportedunsupported pickle protocol: %dargument must have 'read' , 'readline' attributespickle protocol %d asked for; highest available protocol %dargument must have 'write' attributeglobal , instance pickles not supported.attempt getvalue() non-list-based picklerunexpected data in internal listbinstring pickle has negative byte countno int int expected in memocan't pickle %s: import of module %s failedcan't pickle %s: attribute lookup %s.%s failedcan't pickle %s: it's not same object %s.%scan't pickle %s: extension code %s isn't integercan't pickle %s: extension code %ld out of rangecould not convert string intlong pickle has negative byte countcould not convert string floatbinunicode pickle has negative byte countunregistered extension code %ld_inverted_registry[%ld] isn't 2-tuple of stringsa load persistent id instruction encountered, 

if close enough, there's piece says

can't pickle %s: attribute lookup %s.%s failed 

now, if download python sources, can find piece of code responsible raising exception in function static int save_global(picklerobject *self, pyobject *args, pyobject *name) of ./modules/cpickle.c:

klass = pyobject_getattrstring(mod, name_str); if (klass == null) {     cpickle_errformat(picklingerror,                       "can't pickle %s: attribute lookup %s.%s "                       "failed",                       "oss", args, module, global_name);     goto finally; } 

so, best can debug error format string differently (probably providing pystring_as_string((pystringobject *)name), recompile , install modified version of python.

yeah, know that's bad. had same problem myself.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -