我正在尝试使用 python 的 ftplib
上传大量文件。
我应该捕获哪种异常以确保问题是连接错误(以便我可以重新连接)?
编辑:
我在这种情况下尝试了 all_errors
:
- 通过
ftplib
连接到 FTP 服务器并在文件上传前暂停应用程序(通过调试器) - 通过服务器关闭连接
- 恢复申请
使用此代码:
try:
self.f.cwd(dest)
return self.f.storbinary(('STOR '+n).encode('utf-8'), open(f,'rb'))
except ftplib.all_errors as e:
print e
捕获到异常,但 all_errors
为空:
e EOFError:
args tuple: ()
message str:
最佳答案
您可以在文档中查找:http://docs.python.org/2/library/ftplib.html#ftplib.error_reply
另外不要忘记:http://docs.python.org/2/library/ftplib.html#ftplib.all_errors
关于python - 捕获由 ftplib 中的连接错误引起的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14303548/