我在我的Python代码中使用Paramiko(用于SFTP)。除了每次导入或调用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特定函数调用之前添加以下代码,可以消除这个警告。但是无论如何都会出现这个警告。
如果有帮助的话,这是打印警告的第三方库中的代码:
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)
如果您知道如何解决这个问题,请帮助我关闭此警告。