[paramiko] paramiko API changes in 1.6

Dony Pierre Pierre.Dony at nbb.be
Tue Mar 13 01:22:17 PDT 2007


Robey,

Thanks a lot for your help. It works now fine.

paramiko.util.log_to_file('ssh-cmd.log')

client = paramiko.Transport((hostname,hostport))
client.connect(username=username,password=password)
chan=client.open_session()
chan.exec_command(cmd)

stdout = chan.makefile('rb')

for line in stdout:
        print line.strip('\n')
client.close()

Pierre.

 

-----Original Message-----
From: paramiko-bounces at lag.net [mailto:paramiko-bounces at lag.net] On
Behalf Of Robey Pointer
Sent: lundi 12 mars 2007 19:07
To: paramiko
Subject: [paramiko] paramiko API changes in 1.6

Since I got another bug report off-list about this, I decided this is  
probably worth highlighting:

In 1.6, a lot of the Channel methods changed from returning a True/ 
False success indicator to returning nothing, and raising an  
SSHException on failure.  The reason is that I chose poorly the first  
time around, and returning a True/False success value isn't great  
design.  The channel operations should succeed most of the time, and  
when they don't, that's exceptional -- so it should raise an  
exception! :)

If you had code (using paramiko 1.4 or 1.5.x) like this:

     if not chan.exec_command(...):
         raise Exception(...)

You can just change it to:

     chan.exec_command(...)

and an SSHException will be raised if the call fails.  The same is  
true for the other methods on Channel.

robey


_______________________________________________
paramiko mailing list
paramiko at lag.net
http://mail.lag.net/mailman/listinfo/paramiko

-----------------------------------------
Visit our website! http://www.nbb.be

"DISCLAIMER: The content of this e-mail message should not be
construed as binding on the part of the National Bank of Belgium
(NBB) unless otherwise and previously stated. The opinions
expressed in this message are solely those of the author and do not
necessarily reflect NBB viewpoints, particularly when the content
of this message, or part thereof, is private by nature or does not
fall within the professional scope of its author."




More information about the paramiko mailing list