Paramiko: ssh.exec_command to collect output says open channel in response

╄→гoц情女王★ 提交于 2019-12-07 12:02:50

问题


I have python script with paramiko and ssh somewhat as below

import paramiko

# setup ssh connection this works. no problem.
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn = ssh.connect(MACHINEIP, username=ROOTUSER, password=ROOTUSER_PASSWORD, port=22)

# This first ssh exec works perfect. 
(sshin1, sshout1, ssherr1) = ssh.exec_command(cmd1)

# When I print the output of 2nd and 3rd ssh exec, I get output saying of channel open
(sshin2, sshout2, ssherr2) = ssh.exec_command(cmd2)
print sshout2
(sshin3, sshout3, ssherr3) = ssh.exec_command(cmd3)
print sshout3

Channel open messages in output when exec_command is used more than once to collect output:

<paramiko.ChannelFile from <paramiko.Channel 2 (open) window=2097152 
   -> <paramiko.Transport at 0x1d42bd0L (cipher aes128-ctr, 128 bits) 
(active; 1 open channel(s))>>>

<paramiko.ChannelFile from <paramiko.Channel 6 (open) window=2097152 
   -> <paramiko.Transport at 0x1d42bd0L (cipher aes128-ctr, 128 bits) 
(active; 2 open channel(s))>>>

How can I close this open channel? Or any solution on this? I am using python 2.7.


回答1:


Should have used as sshout.read() and rather I used sshout only while printing.



来源:https://stackoverflow.com/questions/20951690/paramiko-ssh-exec-command-to-collect-output-says-open-channel-in-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!