Python Paramiko报告”;“传输线程中的EOF”;登录并关闭ssh会话后

Python Paramiko报告”;“传输线程中的EOF”;登录并关闭ssh会话后,python,ssh,paramiko,eof,Python,Ssh,Paramiko,Eof,我正在编写一个脚本,它应该登录到一些网络设备,执行命令并收集一些文件。现在,我似乎遇到了一个问题,即登录之后,在远程主机上没有执行任何操作,ssh连接就会关闭。在检查来自paramiko的调试消息后,我看到以下消息:“传输线程中的EOF”。我在Windows和Linux上用密码和PSK试过,也试过Spur,总是得到相同的EOF。到目前为止,我只对具有不同软件版本的会话边界控制器存在此问题,但无法在其上调试任何东西,而运行调试时甚至无法看到SSH连接发生,可能发生在我无法访问的后台某处 以下是调试

我正在编写一个脚本,它应该登录到一些网络设备,执行命令并收集一些文件。现在,我似乎遇到了一个问题,即登录之后,在远程主机上没有执行任何操作,ssh连接就会关闭。在检查来自paramiko的调试消息后,我看到以下消息:“传输线程中的EOF”。我在Windows和Linux上用密码和PSK试过,也试过Spur,总是得到相同的EOF。到目前为止,我只对具有不同软件版本的会话边界控制器存在此问题,但无法在其上调试任何东西,而运行调试时甚至无法看到SSH连接发生,可能发生在我无法访问的后台某处

以下是调试消息:

Trying to connect to 10.xxx.xxx.xxx (1/3)
starting thread (client mode): 0x57f09d0L
Local version/idstring: SSH-2.0-paramiko_2.1.1
Remote version/idstring: SSH-2.0-Mocana SSH
Connected (version 2.0, client Mocana)
kex algos:[u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-dss', u'ssh-rsa'] client encrypt:[u'aes256-cbc', u'rijndael256-cbc', u'aes192-cbc', u'rijndael192-cbc', u'aes128-cbc', u'rijndael128-cbc', u'3des-cbc', u'arcfour'] server encrypt:[u'aes256-cbc', u'rijndael256-cbc', u'aes192-cbc', u'rijndael192-cbc', u'aes128-cbc', u'rijndael128-cbc', u'3des-cbc', u'arcfour'] client mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False
Kex agreed: diffie-hellman-group1-sha1
Cipher agreed: aes128-cbc
MAC agreed: hmac-md5
Compression agreed: none
kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1>
Switch to new keys ...
Adding ssh-rsa host key for 10.xxx.xxx.xxx: e3afa50cb2380e75cbbd535fb6ceb3fc
userauth is OK
Authentication (password) successful!
Connected to 10.xxx.xxx.xxx
EOF in transport thread

你知道如何进一步调查这个问题,或者根本原因是什么吗?

在break语句之后,脚本终止。。。因此,添加您需要做的工作。

这似乎是由于我试图访问的设备只允许交互式shell,所以我不得不使用paramiko的invoke_shell,对我来说,它基本上是这样工作的:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,username=username,password=password)
channel = ssh.invoke_shell()
channel.send('uname -a\n' )

buff=''
while not buff.endswith('# '): # Checking for returned prompt
    resp = channel.recv(4096)
    buff += resp
print resp

我也有这个想法,但是如果我尝试在ssh.connect via ssh.exec_command()之后执行一个命令,我会得到一个异常,说“ssh会话未激活”。我猜EOF已收到,ssh连接已关闭,执行任何操作都会导致崩溃或引发异常<代码>userauth正常身份验证(密码)成功!传输线程SSH会话中的EOF未激活
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,username=username,password=password)
channel = ssh.invoke_shell()
channel.send('uname -a\n' )

buff=''
while not buff.endswith('# '): # Checking for returned prompt
    resp = channel.recv(4096)
    buff += resp
print resp