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

flxkid theflxkid at
Fri Sep 18 20:22:40 CEST 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
			if row["private_key"] != "":
				sshconn.connect(hostname=row["host"], username=row["username"],
			elif row["password"] != "":
				sshconn.connect(hostname=row["host"], username=row["username"],
password=row["password"], look_for_keys=False, timeout=60)

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


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

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

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.


More information about the Python-list mailing list