gpt4 book ai didi

python - Flask CLI 显示 "TypeError: exceptions must derive from BaseException"

转载 作者:行者123 更新时间:2023-12-05 08:46:55 33 4
gpt4 key购买 nike

当我使用 flask run 从终端运行 Flask 时,如果我的代码有错误,我会看到“TypeError:exceptions must derive from BaseException”而不是实际错误。要调试它,我需要打开浏览器并检查 Werkzeug 调试器中的 exc_info 变量,这并不方便。为什么 Flask 这样做?如何在终端中查看实际错误?

$ FLASK_APP=example flask run

Traceback (most recent call last):
File "[...]/lib/python3.9/site-packages/flask/cli.py", line 356, in __call__
self._flush_bg_loading_exception()
File "[...]/lib/python3.9/site-packages/flask/cli.py", line 344, in _flush_bg_loading_exception
raise exc_info
TypeError: exceptions must derive from BaseException

最佳答案

这是一个 bug在 Flask 2.0 中引入将是 fixed当 Flask 2.0.2 发布时。 CLI 错误地重新引发 sys.exc_info() 而不是仅引发异常对象。在此之前,您可以通过运行 flask run --eager-loading 来关闭延迟加载。

关于python - Flask CLI 显示 "TypeError: exceptions must derive from BaseException",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68710169/

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