paramiko.transport 使用 ssh 连接到远程服务器时抛出运行时 ValueError
paramiko.transport throws runtime ValueError while connecting to remote server using ssh
我是 Python 的初学者,正在尝试为我的项目构建一个应用程序,以使用“Python 2.7 从远程服务器获取日志.11'。我使用“Paramiko 2.0.0”和“cryptography 1.3.2”来完成此任务。当直接从 IDLE 执行时,该脚本工作正常。然后我使用最新的 PyInstaller - 3.2 来创建这个应用程序的可执行文件。但是可执行文件在与服务器创建 ssh 连接时抛出 运行 时间错误。
当执行此 exe 文件时,同时尝试使用以下代码连接到服务器:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='<ip address is hardcoded here>',port=22, username='root', password='<password is hardcoded here>')
最后一行抛出运行时间错误:
“多后端无法在没有后端的情况下进行初始化。如果您在尝试使用 default_backend() 时看到此错误,请尝试卸载并重新安装 cryptography."
如错误消息中所述,我尝试卸载并重新安装 cryptography,但这没有用。
我在 运行 时间内使用“paramiko. util. log_to_file ('C:\Python27\paramiko.log')
”收集日志记录,它显示了以下结果:
DEB [20160510-11:28:40.530] thr=1 paramiko.transport: starting thread (client mode): 0x2b74890L
DEB [20160510-11:28:40.530] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.0.0
DEB [20160510-11:28:40.536] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_4.3
INF [20160510-11:28:40.536] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_4.3)
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] client mac:[u'hmac-md5', u'hmac-sha1', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'hmac-md5', u'hmac-sha1', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Kex agreed: diffie-hellman-group1-sha1
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: MAC agreed: hmac-md5
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Compression agreed: none
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: Unknown exception: Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography.
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\transport.py", line 1757, in run
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\kex_group1.py", line 75, in parse_next
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\kex_group1.py", line 111, in _parse_kexdh_reply
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\transport.py", line 1602, in _verify_key
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\rsakey.py", line 58, in __init__
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\cryptography\hazmat\backends\__init__.py", line 35, in default_backend
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\cryptography\hazmat\backends\multibackend.py", line 33, in __init__
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: ValueError: Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography.
请帮助我理解和调试这个问题,因为我是 Python 的新手并且不太熟悉深入调试 python 代码。
如果分析需要有关脚本的更多信息,请告诉我。
我遇到了同样的问题,使用的是PyInstaller - 2.1,其他版本和你一样。
将 paramiko 降级到 1.17 版并使用 PyInstaller 重建 exe 解决了我的问题,
pip uninstall paramiko
pip install paramiko==1.17
试试这个:
def patch_crypto():
from cryptography.hazmat import backends
try:
from cryptography.hazmat.backends.commoncrypto.backend import backend as be_cc
except ImportError:
be_cc = None
try:
from cryptography.hazmat.backends.openssl.backend import backend as be_ossl
except ImportError:
be_ossl = None
backends._available_backends_list = [
be for be in (be_cc, be_ossl) if be is not None
]
然后
patch_crypto()
我是 Python 的初学者,正在尝试为我的项目构建一个应用程序,以使用“Python 2.7 从远程服务器获取日志.11'。我使用“Paramiko 2.0.0”和“cryptography 1.3.2”来完成此任务。当直接从 IDLE 执行时,该脚本工作正常。然后我使用最新的 PyInstaller - 3.2 来创建这个应用程序的可执行文件。但是可执行文件在与服务器创建 ssh 连接时抛出 运行 时间错误。
当执行此 exe 文件时,同时尝试使用以下代码连接到服务器:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='<ip address is hardcoded here>',port=22, username='root', password='<password is hardcoded here>')
最后一行抛出运行时间错误: “多后端无法在没有后端的情况下进行初始化。如果您在尝试使用 default_backend() 时看到此错误,请尝试卸载并重新安装 cryptography."
如错误消息中所述,我尝试卸载并重新安装 cryptography,但这没有用。
我在 运行 时间内使用“paramiko. util. log_to_file ('C:\Python27\paramiko.log')
”收集日志记录,它显示了以下结果:
DEB [20160510-11:28:40.530] thr=1 paramiko.transport: starting thread (client mode): 0x2b74890L
DEB [20160510-11:28:40.530] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.0.0
DEB [20160510-11:28:40.536] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_4.3
INF [20160510-11:28:40.536] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_4.3)
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] client mac:[u'hmac-md5', u'hmac-sha1', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'hmac-md5', u'hmac-sha1', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Kex agreed: diffie-hellman-group1-sha1
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: MAC agreed: hmac-md5
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Compression agreed: none
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: Unknown exception: Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography.
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\transport.py", line 1757, in run
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\kex_group1.py", line 75, in parse_next
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\kex_group1.py", line 111, in _parse_kexdh_reply
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\transport.py", line 1602, in _verify_key
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\rsakey.py", line 58, in __init__
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\cryptography\hazmat\backends\__init__.py", line 35, in default_backend
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\cryptography\hazmat\backends\multibackend.py", line 33, in __init__
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: ValueError: Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography.
请帮助我理解和调试这个问题,因为我是 Python 的新手并且不太熟悉深入调试 python 代码。 如果分析需要有关脚本的更多信息,请告诉我。
我遇到了同样的问题,使用的是PyInstaller - 2.1,其他版本和你一样。
将 paramiko 降级到 1.17 版并使用 PyInstaller 重建 exe 解决了我的问题,
pip uninstall paramiko
pip install paramiko==1.17
试试这个:
def patch_crypto():
from cryptography.hazmat import backends
try:
from cryptography.hazmat.backends.commoncrypto.backend import backend as be_cc
except ImportError:
be_cc = None
try:
from cryptography.hazmat.backends.openssl.backend import backend as be_ossl
except ImportError:
be_ossl = None
backends._available_backends_list = [
be for be in (be_cc, be_ossl) if be is not None
]
然后
patch_crypto()