def get_transport(socket): """ Get transport. """ try: t = paramiko.Transport(socket) t.start_client() except paramiko.SSHException: print 'Secure Shell negotiation failed.' traceback.print_exc() sys.exit(1) Here is it being called: mysock = ssh_connect(hostname, port) get_transport(mysock) try: t = paramiko.Transport(mysock) t.start_client() except paramiko.SSHException: print 'Secure Shell negotiation failed.' sys.exit(1) I get this: $ python pssh.py Secure Shell negotiation failed.