SFTP Paramiko (Python) - 导入错误 DLL 加载失败 - 不是有效的 Win32 应用程序
SFTP Paramiko (Python) - Import Error DLL Load Failed - Not a valid Win32 Application
我是一个新手Python程序员。我正在使用一个简单的 paramiko 脚本来下载一个 SFTP 文件。它最近开始抛出以下错误:ImportError:DLL 加载失败:%1 不是有效的 Win32 应用程序。它可以毫无问题地工作几个月。我在 Windows 7 64 位上使用 paramiko 2.1.2、密码学 1.8.1 和 Python 2.7.12 32 位。
>>> t = paramiko.Transport((hostname, port))
>>> t.connect(username=username, password=password)
No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\paramiko\transport.py", line 1073, in connect
self.start_client()
File "C:\Python27\lib\site-packages\paramiko\transport.py", line 493, in start_client
raise e
ImportError: DLL load failed: %1 is not a valid Win32 application.
我试过卸载并重新安装。回滚到以前的版本,但没有解决此错误。我很感激有人能提供的任何帮助。
日志文件:
DEB [20170320-10:23:43.359] thr=1 paramiko.transport: starting thread (client mode): 0x29f2250L
DEB [20170320-10:23:43.359] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.1.2
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-WS_FTP-SSH_7.7
INF [20170320-10:23:43.407] thr=1 paramiko.transport: Connected (version 2.0, client WS_FTP-SSH_7.7)
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: kex algos:[u'diffie-hellman-group1-sha1', u'diffie-hellman-group14-sha1'] server key:[u'ssh-dss', u'ssh-rsa'] client encrypt:[u'aes256-ctr', u'aes192-ctr', u'aes128-ctr', u'3des-cbc'] server encrypt:[u'aes256-ctr', u'aes192-ctr', u'aes128-ctr', u'3des-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Kex agreed: diffie-hellman-group1-sha1
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: MAC agreed: hmac-sha1-96
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Compression agreed: none
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: Unknown exception: DLL load failed: %1 is not a valid Win32 application.
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\transport.py", line 1783, in run
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: self.kex_engine.parse_next(ptype, m)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\kex_group1.py", line 75, in parse_next
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: return self._parse_kexdh_reply(m)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\kex_group1.py", line 111, in _parse_kexdh_reply
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: self.transport._verify_key(host_key, sig)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\transport.py", line 1628, in _verify_key
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: key = self._key_info[self.host_key_type](Message(host_key))
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\rsakey.py", line 59, in __init__
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: ).public_key(default_backend())
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 74, in default_backend
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: _default_backend = MultiBackend(_available_backends())
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 31, in _available_backends
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: "cryptography.backends"
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 2308, in resolve
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: module = __import__(self.module_name, fromlist=['__name__'], level=0)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.hazmat.backends.openssl.backend import backend
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 16, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography import utils, x509
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\x509\__init__.py", line 7, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.x509.base import (
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\x509\base.py", line 16, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.x509.extensions import Extension, ExtensionType
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\x509\extensions.py", line 19, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.hazmat.primitives import constant_time, serialization
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\primitives\constant_time.py", line 9, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.hazmat.bindings._constant_time import lib
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: ImportError: DLL load failed: %1 is not a valid Win32 application.
ERR [20170320-10:23:43.780] thr=1 paramiko.transport:
这意味着您拥有 64 位操作系统,并且您使用的是 32 位软件包。当机器的基本架构和安装的包不匹配时会出现此错误。
- 安装 Microsoft Visual C++ compiler for python
- pip 安装轮
- pip 安装参数
我试过下面的程序,效果很好。
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.5.7', username='user', password='mysecretkeya')
uptime = ssh.exec_command("uptime")
print uptime
我的最终解决方案是卸载 python 2.7 32 位和 paramiko。然后重新安装 python 2.1 64 位并重新安装 paramiko。这纠正了我的错误。
在 64 位机器上重新安装 python 2.7 后,我强行设置了 wheel 和 paramikore-installation
pip install --upgrade --force paramiko
我是一个新手Python程序员。我正在使用一个简单的 paramiko 脚本来下载一个 SFTP 文件。它最近开始抛出以下错误:ImportError:DLL 加载失败:%1 不是有效的 Win32 应用程序。它可以毫无问题地工作几个月。我在 Windows 7 64 位上使用 paramiko 2.1.2、密码学 1.8.1 和 Python 2.7.12 32 位。
>>> t = paramiko.Transport((hostname, port))
>>> t.connect(username=username, password=password)
No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\paramiko\transport.py", line 1073, in connect
self.start_client()
File "C:\Python27\lib\site-packages\paramiko\transport.py", line 493, in start_client
raise e
ImportError: DLL load failed: %1 is not a valid Win32 application.
我试过卸载并重新安装。回滚到以前的版本,但没有解决此错误。我很感激有人能提供的任何帮助。
日志文件:
DEB [20170320-10:23:43.359] thr=1 paramiko.transport: starting thread (client mode): 0x29f2250L
DEB [20170320-10:23:43.359] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.1.2
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-WS_FTP-SSH_7.7
INF [20170320-10:23:43.407] thr=1 paramiko.transport: Connected (version 2.0, client WS_FTP-SSH_7.7)
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: kex algos:[u'diffie-hellman-group1-sha1', u'diffie-hellman-group14-sha1'] server key:[u'ssh-dss', u'ssh-rsa'] client encrypt:[u'aes256-ctr', u'aes192-ctr', u'aes128-ctr', u'3des-cbc'] server encrypt:[u'aes256-ctr', u'aes192-ctr', u'aes128-ctr', u'3des-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Kex agreed: diffie-hellman-group1-sha1
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: MAC agreed: hmac-sha1-96
DEB [20170320-10:23:43.407] thr=1 paramiko.transport: Compression agreed: none
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: Unknown exception: DLL load failed: %1 is not a valid Win32 application.
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\transport.py", line 1783, in run
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: self.kex_engine.parse_next(ptype, m)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\kex_group1.py", line 75, in parse_next
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: return self._parse_kexdh_reply(m)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\kex_group1.py", line 111, in _parse_kexdh_reply
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: self.transport._verify_key(host_key, sig)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\transport.py", line 1628, in _verify_key
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: key = self._key_info[self.host_key_type](Message(host_key))
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\paramiko\rsakey.py", line 59, in __init__
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: ).public_key(default_backend())
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 74, in default_backend
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: _default_backend = MultiBackend(_available_backends())
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 31, in _available_backends
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: "cryptography.backends"
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 2308, in resolve
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: module = __import__(self.module_name, fromlist=['__name__'], level=0)
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.hazmat.backends.openssl.backend import backend
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 16, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography import utils, x509
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\x509\__init__.py", line 7, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.x509.base import (
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\x509\base.py", line 16, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.x509.extensions import Extension, ExtensionType
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\x509\extensions.py", line 19, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.hazmat.primitives import constant_time, serialization
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: File "C:\Python27\lib\site-packages\cryptography\hazmat\primitives\constant_time.py", line 9, in <module>
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: from cryptography.hazmat.bindings._constant_time import lib
ERR [20170320-10:23:43.780] thr=1 paramiko.transport: ImportError: DLL load failed: %1 is not a valid Win32 application.
ERR [20170320-10:23:43.780] thr=1 paramiko.transport:
这意味着您拥有 64 位操作系统,并且您使用的是 32 位软件包。当机器的基本架构和安装的包不匹配时会出现此错误。
- 安装 Microsoft Visual C++ compiler for python
- pip 安装轮
- pip 安装参数
我试过下面的程序,效果很好。
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.5.7', username='user', password='mysecretkeya')
uptime = ssh.exec_command("uptime")
print uptime
我的最终解决方案是卸载 python 2.7 32 位和 paramiko。然后重新安装 python 2.1 64 位并重新安装 paramiko。这纠正了我的错误。
在 64 位机器上重新安装 python 2.7 后,我强行设置了 wheel 和 paramikore-installation
pip install --upgrade --force paramiko