gpt4 book ai didi

python - 如何为 flask 中的外部库禁用 ExtDeprecationWarning

转载 作者:太空狗 更新时间:2023-10-29 20:15:22 25 4
gpt4 key购买 nike

当我运行我的脚本时,我得到了这个输出:

/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.marshmallow is deprecated, use flask_marshmallow instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful is deprecated, use flask_restful instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.fields is deprecated, use flask_restful.fields instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.reqparse is deprecated, use flask_restful.reqparse instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restplus is deprecated, use flask_restplus instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.restful.representations is deprecated, use flask_restful.representations instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
.format(x=modname), ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.migrate is deprecated, use flask_migrate instead.
.format(x=modname), ExtDeprecationWarning

我真的不关心这个,因为外部库导致了这个。我无法更新这些库,因为我不拥有它们,而且我看到有几个库有待处理的拉取请求。

我怎样才能得到一些平静和安静?

最佳答案

从 Flask 1.0 开始,flask.ext 不存在。没有修复这些导入的包将无法工作。


首先,您应该关心这一点,因为您使用的包不是最新的。报告一个错误,他们应该切换到使用直接导入名称,例如 flask_sqlalchemy,而不是 flask.ext 导入 Hook 。

添加 warnings.simplefilter行来过滤掉这些警告。在执行任何会引发警告的导入之前,您可以将它放在配置应用程序的任何位置。

import warnings
from flask.exthook import ExtDeprecationWarning

warnings.simplefilter('ignore', ExtDeprecationWarning)

关于python - 如何为 flask 中的外部库禁用 ExtDeprecationWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38079200/

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