Reputation: 21
I can ssh to a server using pexpect and have no problems logging in and running commands. However, I would like to switch to using paramiko to make the ssh connections so I can take advantage of some of the other paramiko modules. However, when I use paramiko I get the error:
sock.connect((hostname, port))
File "<string>", line 1, in connect
socket.error: [Errno 113] No route to host
I don't understand why it says no route to host, as I can definitely reach the node as pexpect showed me or by just simply ssh'ing to the node.
Any help in what might be the issue here would be greatly appreciated. I am not sure how to even go about troubleshooting this.
I am running paramiko with debugs enabled like this, but I don't get any debug messages and the script just fails immediately:
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
Upvotes: 0
Views: 1981
Reputation: 14855
It would be helpful if you could post a simplified example of the code you're using.
Check to make sure that name resolution is happening properly:
socket.gethostbyname(hostname)
Also, I'm not sure why you're using socket
directly? Or is that part of the stacktrace and error message you get when you
You should be able to accomplish what you want with something like this:
from paramiko.client import SSHClient
client = SSHClient()
client.load_system_host_keys()
client.connect('ssh.example.com')
stdin, stdout, stderr = client.exec_command('ls -l')
print stdout
It would be more helpful if you supplied the full error message, stacktrace, and the code that you're using.
Upvotes: 1