Python 华为的paramiko路由器

Python 华为的paramiko路由器,python,paramiko,huawei-mobile-services,Python,Paramiko,Huawei Mobile Services,朋友们, 有人知道为什么这段代码在cisco路由器上运行得很好,但在华为路由器上,它保持不变,无法完成吗 import paramiko ssh_RT = paramiko.SSHClient() ssh_RT.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_RT.connect( sIP, port=22, username=uuu, password=sss, timeout=5,

朋友们, 有人知道为什么这段代码在cisco路由器上运行得很好,但在华为路由器上,它保持不变,无法完成吗

import paramiko

ssh_RT = paramiko.SSHClient()
ssh_RT.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh_RT.connect(
    sIP,
    port=22,
    username=uuu,
    password=sss,
    timeout=5,
    look_for_keys=False,
    allow_agent=False
)

sComando = 'dis ip int br'
# sComando = 'sh ip int br'

stdin, stdout, stderr = ssh_RT.exec_command(sComando)
sOut = stdout.read().decode()
print (sOut)
ssh_RT.close()
成功了。像这样:

def receive_data(pLenght, pTimeout):
    for x in range(pTimeout):    
        time.sleep(1)
        r = channel.recv(2024)
        z = r.decode('utf-8','ignore')
        if len(z) > pLenght:
            break
    return z


channel = ssh_RT.invoke_shell()
channel.send('dis ip int br\n')
out = receive_data(50,5)

在第二台路由器上,连接可能被防火墙断开,“连接”可能超时,但很难确定。我不这么认为,因为直接命令路由器是可能的。通过netmiko(另一个图书馆)可以查阅。。。但netmiko的速度非常慢…stdin,stdout,stderr=ssh_RT.exec_命令(sComando)我怀疑这可能是字符编码。出于某种原因,exec_命令不适用于华为路由器。我怀疑。这就是为什么我问你是否可以做
sshuuu@sss命令行上的dis ip int br
。这相当于执行命令。。。你是对的。您所表示的ssh命令(在命令行上)正在崩溃…@MartinPrikryl关于使用invoke_shell而不是exec_命令的最后一个问题:我在另一篇文章中看到,您不建议使用invoke_shell。该警报是否是因为invoke_shell需要更多的代码控制才能关闭通道?