paramiko SSHException:在Alactel Lucent Omniswitch 6000上使用exec_command时,通道已关闭

时间:2016-09-15 08:46:12

标签: python paramiko

我跑的时候:

def conn_string(cmd, switch_IP, uname, pword):
 try:
     ssh = paramiko.SSHClient()
     ssh.load_system_host_keys()
     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     ssh.connect(switch_IP, username=uname, password=pword, port=22)
     stdin, stdout, stderr = ssh.exec_command(command=cmd, timeout=60)
     output = stdout.read()
     current_res = output.decode('ascii')
     print(current_res)
     return current_res
 except paramiko.AuthenticationException:
     print("\n Authentication Failed!")
     exit()
 except paramiko.SSHException:
     print("\n Issues with SSH service!!!")
     exit()
 except BaseException as e:
     print(str(e))
     exit()

if __name__ == '__main__':
 switch_IP = input("Enter switch IP address: ")
 u_name = "abc"
 p_word = "xyz"
 res = conn_string("show configuration snapshot", switch_IP, u_name, p_word)

我收到SSH异常:频道已关闭

但是当我跑步时:

    conn = paramiko.SSHClient()
    conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    conn.connect(switch_IPAddress, port=22, username=u_name,
                    password=p_word,
                    look_for_keys=False, allow_agent=False)

    con = conn.invoke_shell()
    output = con.recv(65535)
    final_output = output.decode('ascii')
    print(final_output)

    con.send("show configuration snapshot")
    time.sleep(.5)
    output = con.recv(65535)
    final_output = output.decode('ascii')
    print(final_output)

它只显示设备信息和没有任何输出或错误的命令

cmd在交换机控制台上正常工作。 如果我在cisco开关上使用相同的代码(当然使用diff命令),它可以完美地工作但是在alcatel开关上失败了。请帮帮我。

0 个答案:

没有答案
相关问题