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


Groups > comp.lang.python > #15295 > unrolled thread

Re: Paramiko Question

Started byMRAB <python@mrabarnett.plus.com>
First post2011-11-03 15:38 +0000
Last post2011-11-03 15:38 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#15295 — Re: Paramiko Question

FromMRAB <python@mrabarnett.plus.com>
Date2011-11-03 15:38 +0000
SubjectRe: Paramiko Question
Message-ID<mailman.2408.1320334718.27778.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web