问题描述
我将ftplib与Python 3.6.9结合使用,以列出服务器上的新文件并下载它们。该服务器会定期断开连接,并出现以下两个错误之一:
unset
解决方案似乎很简单,捕获异常,然后重试。不幸的是,我似乎无法捕捉到异常。这很奇怪,因为此解决方案确实可以在下载文件的方法中工作。仅列出目录的方法无法捕获异常。
ConnectionResetError: [Errno 104] Connection reset by peer
ftplib.error_temp: 426 Data connection unexpectedly closed
我收到的错误消息是:
def find_files_and_directories(self,current_path):
for attempt in range(1,self.nr_of_attempts):
try:
return self.connection.mlsd(path=current_path)
except ConnectionResetError as msg:
self.reconnect()
continue
except ftplib.all_errors as msg:
if str(msg)[:3] == '425':
time.sleep(self.wait_time)
continue
else:
self.reconnect()
continue
except ftplib.error_temp as msg:
log.add_message('Exception caught as error_temp',msg)
raise msg
except Exception as e:
log.add_message('Exception was caught by last except in ' +
'find_files_and_directories. That should not ' +
'have happened. ',e)
raise e
else:
self.failure()
这似乎很简单,我想念什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)