ssh会话不活跃paramiko

时间:2015-01-20 10:19:36

标签: python session ssh paramiko

我有一段代码,我试图通过使用Python的paramiko库通过ssh连接到Windows机器。我第一次连接,它是成功的。但第二次,我收到错误" SSH会话未激活"。是因为我试图在两个不同的功能中使用它吗?代码如下所示:

class setup():#gets executed first
    @test.subsection
    def test_connection(self):
        #connecting first time
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect("8.29.9.131", username = "user", password = "pass")
        ssh.close()

class test1():#gets executed next
    @test.setup
    def setup(self): #runs first
        #connecting second time
        self.ssh = paramiko.SSHClient()
        self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.ssh.connect("8.29.9.131", username = "user", password = "pass")

    @test.maintest
    def main_test(self): #runs after setup section above
        in, out, err = self.ssh.exec_command("cmd /c C:\\\Python27\\\Scripts\\\module.py")
        print out.readlines()
        self.ssh.close()

回溯看起来像这样:

2015-01-20T15:42:23: %test-ERROR:     stdin, stdout, stderr = self.ssh.exec_command("cmd /c C:\\\Python27\\\Scripts\\\module.py")
2015-01-20T15:42:23: %test-ERROR:   File "build/bdist.linux-     x86_64/egg/paramiko/client.py", line 341, in exec_command
2015-01-20T15:42:23: %test-ERROR:     chan = self._transport.open_session()
2015-01-20T15:42:23: %test-ERROR:   File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 615, in open_session
2015-01-20T15:42:23: %test-ERROR:     max_packet_size=max_packet_size)
2015-01-20T15:42:23: %test-ERROR:   File "build/bdist.linux-x86_64/egg/paramiko/transport.py", line 696, in open_channel
2015-01-20T15:42:23: %test-ERROR:     raise SSHException('SSH session not active')

0 个答案:

没有答案