15 messages in com.googlegroups.django-usersRe: ordinal not in range(128) + ezPyC...
FromSent OnAttachments
elementalMay 13, 2007 4:14 am 
Malcolm TredinnickMay 13, 2007 4:32 am 
elementalMay 13, 2007 5:07 am 
Benjamin SlavinMay 13, 2007 10:55 am 
elementalMay 14, 2007 12:17 am 
elementalMay 14, 2007 1:59 am 
Malcolm TredinnickMay 14, 2007 2:10 am 
elementalMay 14, 2007 2:40 am 
elementalMay 14, 2007 5:01 am 
Benjamin SlavinMay 14, 2007 6:27 am 
Forest BondMay 14, 2007 7:02 am 
Benjamin SlavinMay 14, 2007 7:21 am 
Forest BondMay 14, 2007 8:06 am 
elementalMay 14, 2007 6:33 pm 
Forest BondMay 14, 2007 6:54 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: ordinal not in range(128) + ezPyCryptoActions...
From:Benjamin Slavin (benj@gmail.com)
Date:May 13, 2007 10:55:04 am
List:com.googlegroups.django-users

On 5/13/07, elemental <kai.@gmail.com> wrote:

UnicodeDecodeError at /register/ 'ascii' codec can't decode byte 0xb4 in position 0: ordinal not in range(128)

For reference, here is the save portion of the model:

def save(self): key = ezPyCrypto.key(512) self.passport = key.encString(self.passport)

First, I'd recommend making a slight modification to this... you're continually re-encrypting the passport information... so if you call .save() twice you'll get an double-encrypted .passport value.

One option can be found in the Satchmo Project's handling of credit card data. [0] They use a storeCC method and a decryptedCC property to handle encryption/decryption.

Another option is to use getter and setter methods, and access them via a property... this way encryption and decryption are transparent operations (this may or may not be desirable, depending on your environment).

So, for example: class YourModel(models.Model): ... encrypted_passport = models.CharField(...) def get_passport(self): #decrypt and return decrypted value def set_passport(self, value): #encrypt and store in self.encrypted_passport passport = property(get_passport, set_passport)

Getting back to your original question, this sounds like you're getting binary data back from encString (it looks like it's built on top of pycrypto[1], so that's likely). You can try the following to convert it to ASCII text before saving it: self.passport = key.encString(...).encode('base64')

Then, just run .decode('base64') on the string before running decryption.

Hope that helps, - Ben

[0]
http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/payment/models.py [1] http://www.amk.ca/python/code/crypto.html