9

I am running flask, pymongo and flask-login as a stack.

My flask app is running fine locally, but once I deploy it with uwsgi on nginx, I get a strange unicode error from flask_login extension.

In short:

TypeError: decoding Unicode is not supported

Traceback:

[pid: 21753|app: 0|req: 5/5] 84.207.253.34 () {38 vars in 600 bytes} [Thu Jun 13 16:51:08 2013] GET / => generated 0 bytes in 4 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
Traceback (most recent call last):
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1473, in full_dispatch_request
    rv = self.preprocess_request()
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1666, in preprocess_request
    rv = func()
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask_login.py", line 311, in _load_user
    deleted = self._session_protection()
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask_login.py", line 325, in _session_protection
    ident = _create_identifier()
  File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask_login.py", line 133, in _create_identifier
    request.headers.get("User-Agent")), 'utf8', errors='replace')
TypeError: decoding Unicode is not supported

Why is this not happening in dev environment? Hence it must be somehow related to uwsgi on nginx. Any suggestions? Many Thanks

4

4 回答 4

17

单独降级flask无法解决问题,因为即使安装flask==0.9也会安装最新的依赖项,这是不好的werkzeug==0.9 因此您最好按此顺序安装以下内容:

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

烧瓶登录,然后可以是最新版本0.1.3。那里没有造成任何伤害。这个堆栈对我有用。

希望这会有所帮助,直到紧急补丁发布。

于 2013-06-13T22:41:42.647 回答
7

我在开发环境中遇到了同样的问题,使用 Flask 0.10 和 Flask-Login 0.1.3

看起来烧瓶 0.10 现在具有 unicode 请求标头,因此在尝试对已编码的字符串进行编码时,烧瓶登录会爆炸...

Flask_login 的人已经在研究它: https ://github.com/maxcountryman/flask-login/issues/78

(编辑)通往暂时幸福的即时之路(如 github 双线程中所见,感谢 Kofalt 和 Kave!)

pip uninstall flask ; pip uninstall werkzeug ; pip uninstall Flask-Login ; pip install werkzeug==0.8.3 ; pip install flask==0.9 ; pip install Flask-Login==0.1.3
于 2013-06-13T17:48:14.647 回答
2

我的叉子解决了这个问题:

https://github.com/jgelens/flask-login/tree/0.1.4

使用安装:

pip install https://github.com/jgelens/flask-login/archive/0f07b8fa783c40d09cb284d442a526f067bab28b.zip#egg=flask-login
于 2013-06-14T07:30:33.143 回答
1

根据 losu S.,这看起来是 Flask 0.10 问题。尝试使用以下命令在您的虚拟环境中安装以前版本的 Flask:

pip install Flask==0.9
于 2013-06-13T18:41:17.723 回答