Quickstart Flask application failing for some reas

2019-02-18 14:40发布

I created a fresh virtualenv environment for a Flask application called flask-test so that I could do some testing. Imagine my surprise when, running the quickstart application, I get the following error:

Honorss-MacBook-Air-2:Desktop Honors$ cd flask-testing
Honorss-MacBook-Air-2:flask-testing Honors$ source bin/activate
(flask-testing)Honorss-MacBook-Air-2:flask-testing Honors$ python app.py
* Restarting with stat
* Debugger is active!
Traceback (most recent call last):
File "app.py", line 10, in <module>
app.run()
File "/Users/Honors/Desktop/flask-testing/lib/python3.5/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/Users/Honors/Desktop/flask-testing/lib/python3.5/site-packages/werkzeug/serving.py", line 633, in run_simple
application = DebuggedApplication(application, use_evalex)
File "/Users/Honors/Desktop/flask-testing/lib/python3.5/site-packages/werkzeug/debug/__init__.py", line 169, in __init__
if self.pin is None:
File "/Users/Honors/Desktop/flask-testing/lib/python3.5/site-packages/werkzeug/debug/__init__.py", line 179, in _get_pin
self._pin, self._pin_cookie = get_pin_and_cookie_name(self.app)
File "/Users/Honors/Desktop/flask-testing/lib/python3.5/site-packages/werkzeug/debug/__init__.py", line 96, in get_pin_and_cookie_name
h.update('cookiesalt')
TypeError: Unicode-objects must be encoded before hashing

The contents of app.py are:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.debug = True
    app.run()

pip list says that the contents of the environment are:

Flask (0.10.1)
Flask-Login (0.3.2)
Flask-WTF (0.12)
itsdangerous (0.24)
Jinja2 (2.8)
MarkupSafe (0.23)
pip (7.1.2)
setuptools (18.2)
Werkzeug (0.11)
wheel (0.24.0)
WTForms (2.0.2)

All of my other virtual environments run as expected.

标签: python flask pip
1条回答
做自己的国王
2楼-- · 2019-02-18 15:19

Seems like a bug: the related issue Werkzeug 0.11 with Flask 0.10.1 and 'app.debug = True' won't start. #798

I create a new virtual environment using python3.5 and meet the same error, but if I don't use the debug mode, it's fine.

And as the issue says, downgrade Werkzeug to 0.10.4 seem works. You can have a try.

查看更多
登录 后发表回答