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

Discussion in 'Python' started by flxkid, Sep 18, 2009.

  1. flxkid

    flxkid Guest

    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
     
    flxkid, Sep 18, 2009
    #1
    1. Advertising

  2. flxkid

    flxkid Guest

    Re: Python based paramiko package acting up on Linux, code works fineon windows

    On Sep 18, 11:22 am, flxkid <> 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
     
    flxkid, Sep 18, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. murali
    Replies:
    1
    Views:
    904
    Phlip
    Jun 25, 2003
  2. ian douglas
    Replies:
    5
    Views:
    190
    88888 Dihedral
    Mar 5, 2013
  3. Wolfgang Strobl
    Replies:
    0
    Views:
    144
    Wolfgang Strobl
    Mar 4, 2013
  4. Terry Reedy
    Replies:
    0
    Views:
    160
    Terry Reedy
    Mar 4, 2013
  5. Tim Golden
    Replies:
    0
    Views:
    160
    Tim Golden
    Apr 19, 2013
Loading...

Share This Page