1

I have just been trying ssh connection with paramiko. Everything looks fine, but in the final step, when calling the close() method to disconnect the client.

Here is my script:

#!/usr/bin/python

import paramiko
import os

ssh = paramiko.SSHClient()
private_key = os.path.expanduser('~/.ssh/id_dsa')
mkey = paramiko.DSSKey.from_private_key_file(private_key,password='JacquiKoala')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('monitor', username='probert', pkey = mkey)
stdin, stdout, stderr = ssh.exec_command('whoami')
print stdout.readlines()
ssh.close

The shell just hangs, I can type stuff, without any result, Ctrl+C or Ctrl+D don't stop the script nor the connection. I have no other way except closing the shell window which is kind of dirty.

I am running Ubuntu 10.10 with python 2.6.6 and paramiko-1.7.4 compiled from sources.

I really don't know what happens; the close() method is correctly executed as a print "blah" after is executed as well, no error message, and still connected without an appropriate way to stop it.

Thanks for helping me :)

Cheers;

Philippe

1 Answer 1

2

TL;DR: You are not calling the function. Do so with ssh.close() instead of ssh.close

ssh.close is a reference to that function. It tells you about the function, it does not call the function. Here is an example:

def a():
    return 6

a
> <function a at 0x108f71aa0>
a()
> 6
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.