你没有太多解释,因为这个库有错误。请参阅BitBucket上的源代码。
ConnectionException 类没有很好地实现:
class ConnectionException(Exception):
"""Exception raised for connection problems
Attributes:
message -- explanation of the error
"""
def __init__(self, host, port):
# Call the base class constructor with the parameters it needs
Exception.__init__(self, host, port)
self.message = 'Could not connect to host:port. %s:%s'
如您所见,格式“无法连接到主机:端口。%s:%s'未填充主机和端口值。
但是,异常的名称很清楚:您有一个连接错误。
不幸的是,错误的详细信息丢失了:
def _start_transport(self, host, port):
'''start the transport and set the ciphers if specified.'''
try:
self._transport = paramiko.Transport((host, port))
# Set security ciphers if set
if self._cnopts.ciphers is not None:
ciphers = self._cnopts.ciphers
self._transport.get_security_options().ciphers = ciphers
except (AttributeError, socket.gaierror):
# couldn't connect
raise ConnectionException(host, port)
您可以尝试获取最后一个错误(不确定):
import sys
sys.exc_info()
注意:我建议您使用另一个库(例如Paramiko)。