Python Paramiko错误

Python Paramiko错误,python,ssh,Python,Ssh,我写了一个python程序。我有conf文件,我在conf文件中编写了路由器配置命令,我想在paramiko中执行这些命令。我有一个问题-错误消息如下。你能帮我吗? 代码: 错误消息: 回溯(最近一次呼叫最后一次): 文件“/configmaker.py”,第13行,在 stdin、stdout、stderror=ssh.exec_命令(str(komut.strip()) exec_命令第370行的文件“/usr/lib/python2.7/dist packages/paramiko/cli

我写了一个python程序。我有conf文件,我在conf文件中编写了路由器配置命令,我想在paramiko中执行这些命令。我有一个问题-错误消息如下。你能帮我吗? 代码:

错误消息:
回溯(最近一次呼叫最后一次):
文件“/configmaker.py”,第13行,在
stdin、stdout、stderror=ssh.exec_命令(str(komut.strip())
exec_命令第370行的文件“/usr/lib/python2.7/dist packages/paramiko/client.py”
chan=自我传输。打开会话()
文件“/usr/lib/python2.7/dist packages/paramiko/transport.py”,第662行,在open_会话中
返回self.open_频道(“会话”)
文件“/usr/lib/python2.7/dist packages/paramiko/transport.py”,第764行,开放频道
提高e
伊奥费罗
尝试使用以下代码:

import paramiko

if __name__ == "__main__":
    ip = "127.0.0.1"
    username = "admin"
    password = "root"

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip,username=username,password=password)
    ssh_transport = ssh.get_transport()

    for command in ("ls /tmp", "date"):
        chan = ssh_transport.open_session()
        chan.exec_command(command)
        exit_code = chan.recv_exit_status()
        stdin = chan.makefile('wb', -1)         # pylint: disable-msg=W0612
        stdout = chan.makefile('rb', -1)
        stderr = chan.makefile_stderr('rb', -1)  # pylint: disable-msg=W0612
        output = stdout.read()
        print output

尝试以下代码,首先将conf文件复制到远程服务器并执行该文件

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host = str(host)
user = 'root'
pw = 'root123'
ssh.connect(host, username=user, password=pw)

filepath = "conf"
remote_path = "/root/qats_tool.tar"

sftp = ssh.open_sftp()
sftp.put(filepath, remote_path)

command="./conf"
stdin, stdout, stderr = ssh.exec_command(command)
sftp.close()
import paramiko

if __name__ == "__main__":
    ip = "127.0.0.1"
    username = "admin"
    password = "root"

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip,username=username,password=password)
    ssh_transport = ssh.get_transport()

    for command in ("ls /tmp", "date"):
        chan = ssh_transport.open_session()
        chan.exec_command(command)
        exit_code = chan.recv_exit_status()
        stdin = chan.makefile('wb', -1)         # pylint: disable-msg=W0612
        stdout = chan.makefile('rb', -1)
        stderr = chan.makefile_stderr('rb', -1)  # pylint: disable-msg=W0612
        output = stdout.read()
        print output
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host = str(host)
user = 'root'
pw = 'root123'
ssh.connect(host, username=user, password=pw)

filepath = "conf"
remote_path = "/root/qats_tool.tar"

sftp = ssh.open_sftp()
sftp.put(filepath, remote_path)

command="./conf"
stdin, stdout, stderr = ssh.exec_command(command)
sftp.close()