Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15295

Re: Paramiko Question

Date 2011-11-03 15:38 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: Paramiko Question
References <CAC11ra14OvaerSdUo3gh4J7Xw8O6LGK3bchP0TzuHc3CtVB-pQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2408.1320334718.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 03/11/2011 09:22, Jacob Abraham wrote:
> Hi All,
>
>        I need help with the below mentioned script. The second time I
> call a.execute, self.transport.open_session() fails with an EOF error.
> Is this a paramiko bug or am I doing something wrong?
>
>
> import paramiko
>
> class Connection(object):
>      def __init__(self, host, username = None, password = None,
> private_key = None, \
>                   port = 22):
>          self.transport = paramiko.Transport((host, port))
>          self.live = True
>          self.transport.connect(username = username, password = password)
>
>      def execute(self, command):
>          channel = self.transport.open_session()
>          channel.exec_command(command)
>          output = channel.makefile('rb', -1).readlines()
>          if output:
>              print output
>          else:
>              print channel.makefile_stderr('rb', -1).readlines()
>
>      def close(self):
>          if self.live:
>              self.transport.close()
>              self.live = False
>
>      def __del__(self):
>          self.close()
>
> if __name__ == '__main__':
>      a= Connection('ip_or_hostname', 'root', '')
>      print a.execute('version')
>      print a.execute('version')
>      print a.execute('version')
>      a.close()
>
I notice that in the 'execute' method you're opening the session, but 
not closing it.
Could that be the cause of the problem?

I also notice that in that method you're printing the output, not 
returning it, but when you call the execute method you're trying to
print the result, which will be None.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Paramiko Question MRAB <python@mrabarnett.plus.com> - 2011-11-03 15:38 +0000

csiph-web