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


Groups > comp.lang.python > #15295

Re: Paramiko Question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'else:': 0.03; '__name__': 0.09; 'eof': 0.09; 'from:addr:python': 0.09; 'host,': 0.09; 'none.': 0.09; 'password)': 0.09; 'username,': 0.09; 'output': 0.10; 'def': 0.14; 'result,': 0.15; "'')": 0.16; "'__main__':": 0.16; 'abraham': 0.16; 'close(self):': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'jacob': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'port))': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'self.close()': 0.16; 'wrote:': 0.18; 'trying': 0.21; 'subject:Question': 0.21; 'problem?': 0.23; 'wrong?': 0.23; 'header:In-Reply-To:1': 0.23; 'all,': 0.27; 'channel': 0.28; 'import': 0.28; 'script.': 0.28; 'second': 0.29; 'print': 0.29; 'class': 0.29; 'closing': 0.30; 'none,': 0.30; 'returning': 0.32; 'error.': 0.32; 'to:addr:python-list': 0.32; 'it.': 0.33; 'header :User-Agent:1': 0.33; 'received:84': 0.34; 'reply- to:addr:python.org': 0.34; 'something': 0.36; 'doing': 0.37; 'but': 0.37; 'could': 0.38; 'help': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'skip:_ 10': 0.40; 'port': 0.40; 'below': 0.63; 'cause': 0.66; 'header:Reply-To:1': 0.70; 'reply- to:no real name:2**0': 0.71; 'username': 0.77; 'session,': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=SZl1h4tu c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=yj_6LXTI0WAA:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=VKdY0qmIQ55J9f3RusYA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Thu, 03 Nov 2011 15:38:33 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Paramiko Question
References <CAC11ra14OvaerSdUo3gh4J7Xw8O6LGK3bchP0TzuHc3CtVB-pQ@mail.gmail.com>
In-Reply-To <CAC11ra14OvaerSdUo3gh4J7Xw8O6LGK3bchP0TzuHc3CtVB-pQ@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2408.1320334718.27778.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1320334718 news.xs4all.nl 6902 [2001:888:2000:d::a6]:57230
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15295

Show key headers only | 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