我在我的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)
如果你知道这个方法,请帮我关闭这个警告。