GoogleCloudPlatform / webapp2

webapp2 is a framework for Google App Engine
https://webapp2.readthedocs.org
Other
141 stars 63 forks source link

webapp2.extra.sessions needs ascii encoding for cookie_name and secret_key, because hmac needs ascii #70

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
from __future__ import unicode_literals

import webapp2

myconfig_dict = {}
myconfig_dict['webapp2_extras.sessions'] = {
    'cookie_name' : 'session_cookie'.encode('ascii'),
    'secret_key'  : 'my-super-secret-key-somemorearbitarythingstosay'.encode('ascii')
}

Without the ascii encoding of the cookie_name and the secret_key an exception 
is raised, when using unicode literals.

HMAC can only handle byte (i.e. ascii) strings as explained here: 
http://bugs.python.org/issue5285

Original issue reported on code.google.com by robert.vos on 29 Oct 2012 at 2:08