如何禁用ExtDeprecationWarning烧瓶中的外部库 [英] How can I disable ExtDeprecationWarning for external libs in flask

查看:361
本文介绍了如何禁用ExtDeprecationWarning烧瓶中的外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  /app/venv/lib/python2.7/site -packages / flask / exthook.py:71:ExtDeprecationWarning:不推荐使用导入flask.ext.sqlalchemy,而改用flask_sqlalchemy。 
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:导入flask.ext.marshmallow已弃用,改用flask_marshmallow。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:正在导入flask.ext.cache已弃用,请改用flask_cache。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:Importing flask.ext.restful is deprecated ,请改用flask_restful。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:Importing flask.ext.restful.fields已弃用,请改用flask_restful.fields。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:Importing flask.ext.restful.reqparse已弃用,请改用flask_restful.reqparse。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:导入flask.ext.restplus已弃用,请改用flask_restplus。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:Importing flask.ext.restful.representations已弃用,请改用flask_restful.representations。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:正在导入flask.ext.script已弃用,改用flask_script。
.format(x = modname),ExtDeprecationWarning
/app/venv/lib/python2.7/site-packages/flask/exthook.py:71:ExtDeprecationWarning:正在导入flask.ext.migrate已弃用,请改用flask_migrate。
.format(x = modname),ExtDeprecationWarning

我并不关心这个,因为外部库引起了这一点。我无法更新这些库,因为我不拥有它们,我看到有几个请求挂起请求。



我该如何获得一些安静和平静? / p>

解决方案

首先,您应该关心这个问题,因为您使用的软件包不符合要求日期。报告应该切换到使用直接导入名称的错误,例如 flask_sqlalchemy ,而不是 flask.ext 导入hook。



添加 警告.simplefilter 行来过滤掉这些警告。您可以将其放置在您配置应用程序的任何地方,然后再执行任何可能引发警告的导入。

$ b from flask.exthook import ExtDeprecationWarning
$ b $ warnings.simplefilter('ignore',ExtDeprecationWarning)


When I run my script, I get this output:

/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

I don't really care about this, because external libs are causing this. I can't update these libs as I don't own them and I see for several there are pull requests pending.

How can I get some peace and quiet?

解决方案

First, you should care about this because the packages you're using aren't up to date. Report a bug that they should switch to using direct import names, such as flask_sqlalchemy, rather than the flask.ext import hook.

Add a warnings.simplefilter line to filter out these warnings. You can place it wherever you're configuring your application, before performing any imports that would raise the warning.

import warnings
from flask.exthook import ExtDeprecationWarning

warnings.simplefilter('ignore', ExtDeprecationWarning)

这篇关于如何禁用ExtDeprecationWarning烧瓶中的外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆