python paramiko socket.error:[Errno 113]没有东道主的路线

时间:2016-05-07 11:59:24

标签: python sockets ssh paramiko

我无法通过paramiko连接到我的主机。虽然连接throgh shell没有问题。

我的代码:

import socket
from paramiko import client
ssh=client.SSHClient()
ssh.load_system_host_keys()
host=socket.gethostbyname("rumo.fritz.box") # works -> host exists
print host
ssh.connect(host,2012,"sshad","MyPassword",timeout=10)
stdin,stdout,stderr=ssh.exec_command("ls -la")
ssh.close()

错误+输出:

192.168.178.37
Traceback (most recent call last):
  File "./rumo_suspend.py", line 20, in <module>
    ssh.connect(host,2012,"sshad","MyPassword",timeout=10)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 296, in connect
    sock.connect(addr)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 113] No route to host

通过shell连接:

ssh -p 2012 sshad@rumo.fritz.box
sshad@rumo.fritz.box's password: 
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-031600-generic x86_64)

0 个答案:

没有答案