[英]Python Paramiko, Attribute Error 'Nonetype' on close when trying to connect
I'm trying to connect through Paramiko to an external SFTP and passing an encrypted config file for the credentials. 我正在尝试通过Paramiko连接到外部SFTP,并为凭据传递加密的配置文件。 When attempting to connect with the following, I get an error for the exception client.close that states AttributeError: 'Nonetype' object has not attribute 'close':
当尝试连接以下内容时,出现异常client.close的错误,该错误指出AttributeError:'Nonetype'对象没有属性'close':
client = None
try:
client = paramiko.Transport(hostname, port)
client.connect(username=username, password=password)
except Exception as e:
client.close()
return 'Cannot connect to SFTP server: ' + str(e.args[-1]), []
# Go
sftp = paramiko.SFTPClient.from_transport(client)
在异常中,您正在调用方法client.close()
,因为方法client.connect
,该方法将引发错误,请删除此方法或为每个可能的错误创建一个例外,以进行代码处理该特定错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.