|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
paramiko & cherrypy not playing well togetherI'm not really sure where to go with this, so I'll try here first. I have some code that when run on its own works just fine. But when I run the same code from inside cherrypy, it generates an error. Here is the code (more info below): import cherrypy 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('/var/www/cherrypy/ SupportAnyPC.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) cherrypy.log(msg="test %s" % sshconn.exec_command("uname -a")[1].readline(), severity=logging.DEBUG) self.sshconns.append(sshconn) def index(self): return ("connected status %s" % self.sshconns [0]._transport.is_authenticated()) index.exposed = True def setup_server(): cherrypy.config.update({'environment': 'production', 'log.screen': False, 'log.error_file': '/var/www/cherrypy/ site.log', 'show_tracebacks': False}) cherrypy.tree.mount(OpenSessions()) OK, so if I access my webpage that runs this, I get an error in my site.log on the on the line where I'm doing cherrypy.log for a simple test. I get an SSHException: Channel Closed. If I remark out that line, the index function shows that the SSH connection is successfully authenticated. If I take the same code and run it in a standalone python program accessing the same sqlite database (and therefore the same SSH server and authentication credentials) it runs just fine. Do you all over here have any clues why this might happen when cherrypy is thrown into the mix? Note that I'm using cherrypy via mod_python from apache. Here is the actual error dump from the log line up: File "/var/www/cherrypy/sapcon.py", line 29, in __init__ stdin, stdout, stderr = sshconn.exec_command("uname -a") File "/usr/local/lib/python2.6/dist-packages/paramiko/client.py", line 350, in exec_command chan.exec_command(command) 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 SSHException: Channel closed. Thanx for any advice. OLIVER --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |