python出现warning_python – 如何使用warnings.filterwarnings来抑制第三方警告

我在我的python代码(sftp)中使用Paramiko。一切都很好,除了每次我导入或调用paramiko功能。此警告将显示:

C:\Python26\lib\site-packages\Crypto\Util\randpool.py:40: RandomPool_Deprecation

Warning: This application uses RandomPool, which is BROKEN in older releases. S

ee http://www.pycrypto.org/randpool-broken

RandomPool_DeprecationWarning)

我知道这与Paramiko使用PyCrypto的一些不赞成功能的事实有关。

我的问题是,是否有办法以编程方式抑制这个警告?

我试过这个:

warnings.filterwarnings(action='ignore', \

category=DeprecationWarning, module='paramiko')

甚至这样:

warnings.filterwarnings(action='ignore', \

category=DeprecationWarning, module='randpool')

之前’import paramiko’语句和在paramiko特定的函数调用之前,但没有任何作用。不管怎样,这个警告一直显示出来。

如果有帮助,这里是打印警告的第三方库中的代码:

在randpool.py中:

from Crypto.pct_warnings import RandomPool_DeprecationWarning

import Crypto.Random

import warnings

class RandomPool:

"""Deprecated. Use Random.new() instead.

See http://www.pycrypto.org/randpool-broken

"""

def __init__(self, numbytes = 160, cipher=None, hash=None, file=None):

warnings.warn("This application uses RandomPool, which is BROKEN in older releases. See http://www.pycrypto.org/randpool-broken",

RandomPool_DeprecationWarning)

如果你知道这个方法,请帮我关闭这个警告。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值