我试图用pysftp库连接到sftp服务器。这是我的代码:
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection("sftp://host", "login", "password", cnopts=cnopts) as sftp:
sftp.listdir()它给了我一个例外:
pysftp.exceptions.ConnectionException:(“主机”,端口)
但我不知道这个例外意味着什么,问题是什么。
发布于 2017-04-19 15:34:07
您没有太多的解释,因为这个库有错误。请参阅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:%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()注意:,我建议您使用另一个库(例如帕拉米科)。
https://stackoverflow.com/questions/43499555
复制相似问题