Pregunta

After upgrading to Flask 0.10, I get this error:

flask.debughelpers.UnexpectedUnicodeError
UnexpectedUnicodeError: A byte string with non-ASCII data was passed to the session system which can only store unicode strings.  Consider base64 encoding your string (String was 'iB\rOU#\xf7BO\x08^\xa6\xd1)v\xad')

Traceback (most recent call last)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 1479, in full_dispatch_request
response = self.process_response(response)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 1693, in process_response
self.save_session(ctx.session, response)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/app.py", line 837, in save_session
return self.session_interface.save_session(self, session, response)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/sessions.py", line 321, in save_session
val = self.get_signing_serializer(app).dumps(dict(session))
File "/srv/www/li/venv/lib/python2.7/site-packages/itsdangerous.py", line 471, in dumps
return self.make_signer(salt).sign(self.dump_payload(obj))
File "/srv/www/li/venv/lib/python2.7/site-packages/itsdangerous.py", line 676, in dump_payload
json = super(URLSafeSerializerMixin, self).dump_payload(obj)
File "/srv/www/li/venv/lib/python2.7/site-packages/itsdangerous.py", line 454, in dump_payload
return self.serializer.dumps(obj)
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/sessions.py", line 82, in dumps
return json.dumps(_tag(value), separators=(',', ':'))
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/sessions.py", line 72, in _tag
return dict((k, _tag(v)) for k, v in iteritems(value))
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/sessions.py", line 72, in <genexpr>
return dict((k, _tag(v)) for k, v in iteritems(value))
File "/srv/www/li/venv/lib/python2.7/site-packages/flask/sessions.py", line 80, in _tag
u'base64 encoding your string (String was %r)' % value)
UnexpectedUnicodeError: A byte string with non-ASCII data was passed to the session system which can only store unicode strings. Consider base64 encoding your string (String was 'iB\rOU#\xf7BO\x08^\xa6\xd1)v\xad')

What the self.save_session(ctx.session, response) for flask/app.py line 1693 gives is this: flask.sessions.SecureCookieSession({'_id': 'iB\rOU#\xf7BO\x08^\xa6\xd1)v\xad', '_flashes': [('message', 'Please log in to access this page.')]})

So, if I read this correctly, the session gives an id that flask tries to unicode (and fails at). I have no clue on how to correct this (emptying my browsers cache to hope for a new session didn't help either). Can anyone give me any suggestions on what I should do?

Kind regards,

Carst

edit: some extra info. My setup uses flask, flask_mail, flask.ext.mongoengine and flask.ext.security; i use MongoEngine: db = flask.ext.mongoengine.MongoEngine(app) and flask-security: user_datastore = flask.ext.security.MongoEngineUserDatastore(db, User, Role) security = flask.ext.security.Security(app, user_datastore)

Edit: it appears to be a double question: Flask Login: TypeError: decoding Unicode is not supported

(hadn't seen it, sorry)

¿Fue útil?

Solución 2

A temporary workaround (thanks to Kave) is downgrading both Flask and Werkzeug:

pip install werkzeug==0.8.3
pip install flask==0.9
pip install Flask-Login==0.1.3

Otros consejos

That's currently an issue with Flask-Login. As far as I know it's fixed in the git version of the extension.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top