我试图在connect()上获得Python paramiko超时。 它适用于许多主机,但特别是一个主机,它永远不会超时。 这是我的代码:
# python3
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
...
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect(hostname="10.68.45.210", username="root", password="a_none_working_pass", timeout=2)
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 307, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 510, in _auth
self._transport.auth_password(username, password)
File "/usr/lib/python3/dist-packages/paramiko/transport.py", line 1166, in auth_password
return self.auth_handler.wait_for_response(my_event)
File "/usr/lib/python3/dist-packages/paramiko/auth_handler.py", line 192, in wait_for_response
event.wait(0.1)
File "/usr/lib/python3.4/threading.py", line 553, in wait
signaled = self._cond.wait(timeout)
File "/usr/lib/python3.4/threading.py", line 294, in wait
gotit = waiter.acquire(True, timeout)
KeyboardInterrupt
我做错了什么?
我已经完成了一个过程,当它挂起时,我会循环获取这些消息:
select(0, NULL, NULL, NULL, {0, 1000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 2000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 4000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 8000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 16000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 32000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 36139}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 1000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 2000}) = 0 (Timeout)
使用Python 2.7.3和3.4.2尝试使用Debian Jessie,两者都在无限循环中挂起。
编辑:似乎与此SO主题相关:Why does Paramiko hang if you use it while loading a module?但有没有办法搁置此问题?
答案 0 :(得分:0)
我与Paramiko connect有同样的超时问题,对我有用的解决方案是将Paramiko更新为支持auth_timeout的最新版本。
session.connect('ipAddress', username='username', pkey=key, timeout=5, banner_timeout=5, auth_timeout=5)