我为名为virtualenv
的Flask应用程序创建了一个全新的flask-test
环境,以便我可以进行一些测试。想象一下,在运行quickstart应用程序时,我收到以下错误:
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
app.py
的内容是:
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
说环境的内容是:
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)
我的所有其他虚拟环境都按预期运行。
答案 0 :(得分:9)
似乎是一个错误:相关问题Werkzeug 0.11 with Flask 0.10.1 and 'app.debug = True' won't start. #798
我使用python3.5创建了一个新的虚拟环境并遇到了同样的错误,但是如果我不使用调试模式,那就没问题了。
正如问题所说,将Werkzeug评级下调至0.10.4似乎有效。你可以尝试一下。