gpt4 book ai didi

python - Flask 0.10 在 session cookie 上给出 unicode 错误

转载 作者:太空狗 更新时间:2023-10-29 22:13:32 24 4
gpt4 key购买 nike

升级到 Flask 0.10 后,我得到这个错误:

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')

flask/app.py 第 1693 行的 self.save_session(ctx.session, response) 给出的是:flask.sessions.SecureCookieSession({'_id': 'iB\rOU#\xf7BO\x08^\xa6\xd1)v\xad', '_flashes': [('message', '请登录访问此页面。 ')]})

因此,如果我没看错的话, session 会给出一个 id,flask 会尝试对其进行 unicode(但失败)。我不知道如何纠正这个问题(清空我的浏览器缓存以希望新 session 也无济于事)。任何人都可以就我应该做什么给我任何建议吗?

亲切的问候,

卡斯特

编辑:一些额外的信息。我的设置使用了 flask、flask_mail、flask.ext.mongoengine 和 flask.ext.security;我使用 MongoEngine: db = flask.ext.mongoengine.MongoEngine(应用程序)和 flask 安全: user_datastore = flask.ext.security.MongoEngineUserDatastore(数据库,用户,角色) security = flask.ext.security.Security(app, user_datastore)

编辑:这似乎是一个双重问题: Flask Login: TypeError: decoding Unicode is not supported

(没看过,抱歉)

最佳答案

这是目前 Flask-Login 的一个问题.据我所知,它已在扩展的 git 版本中修复。

关于python - Flask 0.10 在 session cookie 上给出 unicode 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17097258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com