I wouldn't consider myself an expert with Unicdoe, but I do know that pickle and cPickle use ASCII for serialization. If you have utf-8 characters stored as attributes in the object you're pickling, that could cause the codec error.
On Jun 22, 10:15 pm, Rodrigo Cea <rodrigo...@gmail.com> wrote: > I am having trouble pickling, and then saving to the DB, django models > with Unicode text in them. The site is for Spanish speakers, so we > need our ñs, és and ös. > > I implemented an unlimited undo feature for a Django site, using this > PickleField snippet: > > http://www.djangosnippets.org/snippets/513/. > > I created a model that holds each object's state at a certain > datetime, like so: > > from fields import PickledObjectField > > class UndoRecord(models.Model): > user = models.ForeignKey(User) > pickle = PickledObjectField() > date = models.DateTimeField(auto_now_add=True) > > and then in my views, whenever a user changes something, I save an > UndoRecord like so: > > undo = UndoRecord(user=request.user, pickle=obj) > undo.save() > > This works fine, except when the object that I am saving has non-ASCII > characters in it, which case I get a lovely: > > DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position > 372-373: invalid data. You passed in "crbml_core.models\nMusico\np1\n > (tRp2\n(dp3\nS'foto'\np4\nccopy_reg\n_reconstructor\np5\n > (cdjango.db.models.fields.files\nImageFieldFile\np6\nc__builtin__ > \nobject\np7\nNtRp8\n > (dp9\nS'_committed'\np10\nI01\nsS'_file'\np11\nNsS'name'\np12\nVuploads/ > musicos/235470296_54ae5af3e9_o.jpg > \np13\nsS'closed'\np14\nI00\nsbsS'user_id'\np15\nNsS'visible'\np16\nI1\nsS' > influencias'\np17\nVFaith > No More\np18\nsS'nombre'\np19\nV\xd1\xed\xfa\xf6\np20\nsS'id'\np21\nL2L > \nsb." (<class 'rbml_core.fields.PickledObject'>) > > I have been trying to fix this using the approach show > here:http://www.mail-archive.com/django-users@googlegroups.com/msg67883.html, > but no such luck. > > Unicode errors are my particular achilles' heel, so any help is much > appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---