I’m trying to pass an encrypted query string to another URL.
The following code gives me this error:
UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u04b7′ in
position 7: ordinal not in range(128)
The encryption module is PyCrypto
Running Python 2.5.2 on App Engine
PAGE A
import Crypto
from Crypto.Cipher import ARC4
obj=ARC4.new('stackoverflow')
msg = 'This is my secret msg'
encrypted = obj.encrypt(msg);
self.redirect('/pageb?' + urllib.urlencode({'q': encrypted}))
PAGE B
import Crypto
from Crypto.Cipher import ARC4
encrypted = self.request.get('q')
obj=ARC4.new('stackoverflow')
decrypted = obj.decrypt(encrypted)
get_data = cgi.parse_qs(decrypted)
self.response.out.write(decrypted)
self.response.out.write(pprint.pprint(get_data))
Traceback
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
handler.get(*groups)
File "C:\Program Files\Google\google_appengine\demos\guestbook\guestbook.py", line 47, in get
decrypted = obj.decrypt(encrypted)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u04b7' in position 7: ordinal not in range(128)
General guidelines: add base64 encoding/decoding step in your encrypted stuff.
For the other error, try reading up on unicode & utf-8 encoding of non-ascii characters. You need this step before passing it to your de/encrypt function.