千家信息网

h3c设备使用paramiko模块连接(SSHException:Channel closed)

发表于:2024-10-21 作者:千家信息网编辑
千家信息网最后更新 2024年10月21日,使用产品为:VSR1000,版本号为:Version 7.1.059, ESS 0323L03。问题:使用python语言的paramiko模块,通过ssh协议登录连接VSR设备时报错,提示: par
千家信息网最后更新 2024年10月21日h3c设备使用paramiko模块连接(SSHException:Channel closed)

使用产品为:VSR1000,版本号为:Version 7.1.059, ESS 0323L03。

问题:

使用python语言的paramiko模块,通过ssh协议登录连接VSR设备时报错,提示: paramiko.ssh_excetion.SSHException:Channel closed。详细信息见截图。

paramiko.ssh_exception.SSHException: Channel closed. ===== invoke_shell()

正确的解决方法如下:

H3C设备登录记录#!/user/bin/env pythonimport sysimport paramikoimport timedef Testsshcon(ip,port,username,password):    try:        sshcon=paramiko.SSHClient()        sshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy())        sshcon.connect(ip,port,username,password,compress=True)        #print "ok"        #print 'ipaddress %s,port %d,uername %s,password %s'%(ip,port,username,password)        print "ssh secuees"        cmds=['dis cpu\n','dis version\n']        conn=sshcon.invoke_shell()        for cmd in cmds:            time.sleep(1)            conn.send(cmd)            time.sleep(1)            print "command"            out=conn.recv(1024)            print out        sshcon.close()    except Exception,e:        print "connet error",eif __name__=="__main__":    Testsshcon('10.10.10.10',22,'username','password')
0