gpt4 book ai didi

python - 快速入门 Flask 应用程序因某种原因失败

转载 作者:太空宇宙 更新时间:2023-11-03 12:46:30 25 4
gpt4 key购买 nike

我为名为 flask-test 的 Flask 应用程序创建了一个全新的 virtualenv 环境,以便进行一些测试。想象一下,当我运行 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)

我的所有其他虚拟环境都按预期运行。

最佳答案

似乎是一个错误:相关问题 Werkzeug 0.11 with Flask 0.10.1 and 'app.debug = True' won't start. #798

我用python3.5新建了一个虚拟环境,同样报错,但是如果不使用debug模式就没事。

正如问题所述,将 Werkzeug 降级到 0.10.4 似乎可行。你可以试试。

关于python - 快速入门 Flask 应用程序因某种原因失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33602708/

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