背景

脚本中使用了paramiko,在高版本的3.9Python环境下很丝滑。
给到指定环境因为Python版本不同(3.6),有Warning信息很碍事。

报警信息

image.png

  1. /usr/local/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  2. from cryptography.hazmat.backends import default_backend

解决

import warnings

在导入前

  1. import warnings
  2. warnings.filterwarnings( action = 'ignore' , module = '.*paramiko.*' )
  3. import paramiko

在导入后(试了没用)

  1. import warnings
  2. from cryptography.utils import CryptographyDeprecationWarning
  3. warnings.filterwarnings( "ignore" , category = CryptographyDeprecationWarning )