如何在烧瓶中禁用外部库的ExtDeprecationWarning

Den*_*ene 9 python flask

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

/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
Run Code Online (Sandbox Code Playgroud)

我真的不关心这个,因为外部库正在造成这种情况.我无法更新这些库,因为我没有它们,我看到有几个有待处理的拉请求.

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

dav*_*ism 13

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


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

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

import warnings
from flask.exthook import ExtDeprecationWarning

warnings.simplefilter('ignore', ExtDeprecationWarning)
Run Code Online (Sandbox Code Playgroud)