python 和 paramiko 的奇怪 EOFError
Weird EOFError with python and paramiko
我的代码:
#!/usr/bin/env python
# encoding: utf-8
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.X.X.X',username='user',password='password')
stdin, stdout, stderr=ssh.exec_command("get system status")
type(stdin)
stdout.readlines()
和我想的一样简单,但是 运行 抛出回溯:
Traceback (most recent call last):
File "/Users/adieball/Dropbox/Multiverse/Programming/workspace/FortiNet/src/runCommand.py", line 8, in <module>
ssh.connect('10.X.X.X',username='user',password='password')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/client.py", line 325, in connect
t.start_client()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/transport.py", line 492, in start_client
raise e
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/transport.py", line 1726, in run
ptype, m = self.packetizer.read_message()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/packet.py", line 386, in read_message
header = self.read_all(self.__block_size_in, check_rekey=True)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/packet.py", line 251, in read_all
raise EOFError()
EOFError
我这里有点糊涂,可能是我瞎了,但是我找不到问题所在。
谢谢
显然:通过 "normal" ssh 和 运行 连接此命令工作得很好 :-)
我更改为 python 2.7(Mac 上的默认设置)并完全删除了 3.5 安装。
我现在得到一个不同的错误(虽然仍然是 EOFError):
Traceback (most recent call last):
File "/Users/adieball/Dropbox/Multiverse/Programming/workspace/FortiNet/src/runCommand.py", line 8, in <module>
ssh.connect('10.X.X.X,username='user',password='password')
File "build/bdist.macosx-10.11-intel/egg/paramiko/client.py", line 325, in connect
File "build/bdist.macosx-10.11-intel/egg/paramiko/transport.py", line 492, in start_client
EOFError
如前所述,我可以使用 "normal" ssh 完美地连接到盒子。
我还测试了 python 的连通性:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
try:
s.connect(('10.2.2.254',22))
except Exception, e:
print 'connection failed'
else:
print "success"
s.close()
并且有效(即打印 "success"),但无论出于何种原因,paramiko 似乎无法连接。
我在 python shell 中逐步尝试了我的代码,以查看错误何时发生以及它在
之后发生
ssh.connect('10.X.X.X',username='user',password='password')
感谢您的帮助。我按照你的建议做了,得到了:
DEBUG:paramiko.transport:starting thread (client mode): 0x7fe51d0L
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_1.16.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-a3WzN
INFO:paramiko.transport:Connected (version 2.0, client a3WzN)
DEBUG:paramiko.transport:kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'arcfour', u'aes192-cbc', u'aes256-cbc', u'rijndael-cbc@lysator.liu.se', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr'] server encrypt:[u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'arcfour', u'aes192-cbc', u'aes256-cbc', u'rijndael-cbc@lysator.liu.se', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr'] 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'] server compress:[u'none', u'zlib'] client lang:[u''] server lang:[u''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-md5
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:EOF in transport thread
您好,我在编写远程访问 fortigate 的脚本时遇到了同样的错误。我看你也在试一个forigate
我已经在 "config system global" 下更改了 fortigate 上的配置并且它起作用了(我不知道实际上是哪个更改,它需要一些试验和错误才能知道)
config system global
- set admin-server-cert "Fortinet_Factory"
- set admin-sport 2222
- set admin-ssh-grace-time 20
- set admin-ssh-v1 enable
- set auth-cert "Fortinet_Factory"
- set dh-params 1024
- set fgd-alert-subscription advisory latest-threat
- set gui-theme red
- set gui-wireless-opensecurity enable
- set hostname "FortiGate-VM64"
- set ssh-cbc-cipher disable
- set ssh-hmac-md5 disable
- set strong-crypto disable
- set timezone 04
end
如果您知道哪一个是必不可少的,请告诉我。
我的代码:
#!/usr/bin/env python
# encoding: utf-8
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.X.X.X',username='user',password='password')
stdin, stdout, stderr=ssh.exec_command("get system status")
type(stdin)
stdout.readlines()
和我想的一样简单,但是 运行 抛出回溯:
Traceback (most recent call last):
File "/Users/adieball/Dropbox/Multiverse/Programming/workspace/FortiNet/src/runCommand.py", line 8, in <module>
ssh.connect('10.X.X.X',username='user',password='password')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/client.py", line 325, in connect
t.start_client()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/transport.py", line 492, in start_client
raise e
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/transport.py", line 1726, in run
ptype, m = self.packetizer.read_message()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/packet.py", line 386, in read_message
header = self.read_all(self.__block_size_in, check_rekey=True)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/paramiko/packet.py", line 251, in read_all
raise EOFError()
EOFError
我这里有点糊涂,可能是我瞎了,但是我找不到问题所在。
谢谢
显然:通过 "normal" ssh 和 运行 连接此命令工作得很好 :-)
我更改为 python 2.7(Mac 上的默认设置)并完全删除了 3.5 安装。 我现在得到一个不同的错误(虽然仍然是 EOFError):
Traceback (most recent call last):
File "/Users/adieball/Dropbox/Multiverse/Programming/workspace/FortiNet/src/runCommand.py", line 8, in <module>
ssh.connect('10.X.X.X,username='user',password='password')
File "build/bdist.macosx-10.11-intel/egg/paramiko/client.py", line 325, in connect
File "build/bdist.macosx-10.11-intel/egg/paramiko/transport.py", line 492, in start_client
EOFError
如前所述,我可以使用 "normal" ssh 完美地连接到盒子。 我还测试了 python 的连通性:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
try:
s.connect(('10.2.2.254',22))
except Exception, e:
print 'connection failed'
else:
print "success"
s.close()
并且有效(即打印 "success"),但无论出于何种原因,paramiko 似乎无法连接。 我在 python shell 中逐步尝试了我的代码,以查看错误何时发生以及它在
之后发生ssh.connect('10.X.X.X',username='user',password='password')
感谢您的帮助。我按照你的建议做了,得到了:
DEBUG:paramiko.transport:starting thread (client mode): 0x7fe51d0L
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_1.16.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-a3WzN
INFO:paramiko.transport:Connected (version 2.0, client a3WzN)
DEBUG:paramiko.transport:kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'arcfour', u'aes192-cbc', u'aes256-cbc', u'rijndael-cbc@lysator.liu.se', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr'] server encrypt:[u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'arcfour', u'aes192-cbc', u'aes256-cbc', u'rijndael-cbc@lysator.liu.se', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr'] 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'] server compress:[u'none', u'zlib'] client lang:[u''] server lang:[u''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-md5
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:EOF in transport thread
您好,我在编写远程访问 fortigate 的脚本时遇到了同样的错误。我看你也在试一个forigate
我已经在 "config system global" 下更改了 fortigate 上的配置并且它起作用了(我不知道实际上是哪个更改,它需要一些试验和错误才能知道)
config system global
- set admin-server-cert "Fortinet_Factory"
- set admin-sport 2222
- set admin-ssh-grace-time 20
- set admin-ssh-v1 enable
- set auth-cert "Fortinet_Factory"
- set dh-params 1024
- set fgd-alert-subscription advisory latest-threat
- set gui-theme red
- set gui-wireless-opensecurity enable
- set hostname "FortiGate-VM64"
- set ssh-cbc-cipher disable
- set ssh-hmac-md5 disable
- set strong-crypto disable
- set timezone 04
end
如果您知道哪一个是必不可少的,请告诉我。