我正在使用 pysftp 连接到服务器并向其上传文件。
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
self.sftp = pysftp.Connection(host=self.serverConnectionAuth['host'], port=self.serverConnectionAuth['port'],
username=self.serverConnectionAuth['username'], password=self.serverConnectionAuth['password'],
cnopts=cnopts)
self.sftp.put(localpath=self.filepath+filename, remotepath=filename)
Run Code Online (Sandbox Code Playgroud)
有时它没有错误,但有时它会正确放置文件,但会引发以下异常。该文件由服务器上运行的另一个程序读取和处理,因此我可以看到该文件在那里并且没有损坏
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
self.sftp = pysftp.Connection(host=self.serverConnectionAuth['host'], port=self.serverConnectionAuth['port'],
username=self.serverConnectionAuth['username'], password=self.serverConnectionAuth['password'],
cnopts=cnopts)
self.sftp.put(localpath=self.filepath+filename, remotepath=filename)
Run Code Online (Sandbox Code Playgroud)
我怎样才能防止异常?