Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python based paramiko package acting up on Linux, code works fine onwindows

Reply
Thread Tools

Python based paramiko package acting up on Linux, code works fine onwindows

 
 
flxkid
Guest
Posts: n/a
 
      09-18-2009
I've tried to post to the mailing list for paramiko and contact the
author, but it seems he's having some mailing list problems. Anyways,
I have this small example that works just fine on Windows against
Python 2.6.2, but fails on Ubuntu against 2.6.2. Here is the code:

import subprocess
import os
import re
import paramiko
import sqlite3
import datetime
import base64
import sys
import logging
from paramiko.rsakey import RSAKey

class OpenSessions:
sshconns = []
sqlconn = sqlite3.connect('test.sqlite')

def __init__(self):
self.sqlconn.row_factory = sqlite3.Row
sqlcur = self.sqlconn.cursor()
sqlcur.execute("select host, pub_key, username, password,
private_key from ssh_hosts")
rows = sqlcur.fetchall()
for row in rows:
sshconn = paramiko.SSHClient()
sshconn._system_host_keys.add(row["host"], "ssh-rsa", RSAKey
(data=base64.decodestring(row["pub_key"])))
if row["private_key"] != "":
sshconn.connect(hostname=row["host"], username=row["username"],
pkey=RSAKey(data=base64.decodestring(row["private_key"])))
elif row["password"] != "":
sshconn.connect(hostname=row["host"], username=row["username"],
password=row["password"], look_for_keys=False, timeout=60)
self.sshconns.append(sshconn)

output = ""
for conn in self.sshconns:
print conn.exec_command("uname -a")[1].readline()

exit()

if __name__== '__main__':
sessions = OpenSessions()

The code fails with this trace:
Traceback (most recent call last):
File "test.py", line 41, in <module>
sessions = OpenSessions()
File "test.py", line 36, in __init__
print chan.exec_command("uname -a")[1].readline()
File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py",
line 212, in exec_command
self._wait_for_event()
File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py",
line 1077, in _wait_for_event
raise e
paramiko.SSHException: Channel closed.
Exception in thread Thread-1 (most likely raised during interpreter
shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in
__bootstrap_inner
File "/usr/local/lib/python2.6/dist-packages/paramiko/transport.py",
line 1567, in run
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
'error'

This well beyond my abilities to debug. All I know is that it always
works on Windows, and always fails in Ubuntu (which of course is where
I need use the code). Any suggestions? I know the paramiko mailing
list would probably be the better spot for this, but like I said, its
got some issues right now.

OLIVER


 
Reply With Quote
 
 
 
 
flxkid
Guest
Posts: n/a
 
      09-18-2009
On Sep 18, 11:22*am, flxkid <theflx...@gmail.com> wrote:
> I've tried to post to the mailing list for paramiko and contact the
> author, but it seems he's having some mailing list problems. *Anyways,
> I have this small example that works just fine on Windows against
> Python 2.6.2, but fails on Ubuntu against 2.6.2. *Here is the code:
>
> import subprocess
> import os
> import re
> import paramiko
> import sqlite3
> import datetime
> import base64
> import sys
> import logging
> from paramiko.rsakey import RSAKey
>
> class OpenSessions:
> * * * * sshconns = []
> * * * * sqlconn = sqlite3.connect('test.sqlite')
>
> * * * * def __init__(self):
> * * * * * * * * self.sqlconn.row_factory = sqlite3.Row
> * * * * * * * * sqlcur = self.sqlconn.cursor()
> * * * * * * * * sqlcur.execute("select host, pub_key, username, password,
> private_key from ssh_hosts")
> * * * * * * * * rows = sqlcur.fetchall()
> * * * * * * * * for row in rows:
> * * * * * * * * * * * * sshconn = paramiko.SSHClient()
> * * * * * * * * * * * * sshconn._system_host_keys..add(row["host"], "ssh-rsa", RSAKey
> (data=base64.decodestring(row["pub_key"])))
> * * * * * * * * * * * * if row["private_key"] != "":
> * * * * * * * * * * * * * * * * sshconn.connect(hostname=row["host"], username=row["username"],
> pkey=RSAKey(data=base64.decodestring(row["private_key"])))
> * * * * * * * * * * * * elif row["password"] != "":
> * * * * * * * * * * * * * * * * sshconn.connect(hostname=row["host"], username=row["username"],
> password=row["password"], look_for_keys=False, timeout=60)
> * * * * * * * * * * * * self.sshconns.append(sshconn)
>
> * * * * * * * * output = ""
> * * * * * * * * for conn in self.sshconns:
> * * * * * * * * * * * * print conn.exec_command("uname -a")[1].readline()
>
> * * * * * * * * exit()
>
> if __name__== '__main__':
> * * * * sessions = OpenSessions()
>
> The code fails with this trace:
> Traceback (most recent call last):
> * File "test.py", line 41, in <module>
> * * sessions = OpenSessions()
> * File "test.py", line 36, in __init__
> * * print chan.exec_command("uname -a")[1].readline()
> * File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py",
> line 212, in exec_command
> * * self._wait_for_event()
> * File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py",
> line 1077, in _wait_for_event
> * * raise e
> paramiko.SSHException: Channel closed.
> Exception in thread Thread-1 (most likely raised during interpreter
> shutdown):
> Traceback (most recent call last):
> * File "/usr/lib/python2.6/threading.py", line 525, in
> __bootstrap_inner
> * File "/usr/local/lib/python2.6/dist-packages/paramiko/transport.py",
> line 1567, in run
> <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
> 'error'
>
> This well beyond my abilities to debug. *All I know is that it always
> works on Windows, and always fails in Ubuntu (which of course is where
> I need use the code). *Any suggestions? *I know the paramiko mailing
> list would probably be the better spot for this, but like I said, its
> got some issues right now.
>
> OLIVER


Was a bug in paramiko channel.py in the _wait_for_event function. All
fixed up now.

OLIVER
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
from datetime.datetime import today not working. python2.6.4 onwindows Joshua Kordani Python 0 01-07-2010 05:07 AM
How can I find the exact version of a different Java process (onWindows) dw Java 7 08-05-2009 08:28 PM
Seriously, what are minimum requirements for running Youtube onWindows 98 SE platform. Jeneric Computer Support 2 12-08-2007 08:17 PM
Problem with os.listdir and delay with unreachable network drives onWindows Read Roberts Python 0 12-22-2004 11:02 PM
Cannot acces my web page onwindows 2003 server. Jensen Bredal ASP .Net 3 11-25-2004 08:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57