python - 捕获由 ftplib 中的连接错误引起的异常

标签 python exception ftplib

我正在尝试使用 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:    

最佳答案

关于python - 捕获由 ftplib 中的连接错误引起的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14303548/

相关文章:

ruby-on-rails - 是什么导致了这个 rails ioerror closed stream?

python - 我可以使用 Python 将内存中的对象上传到 FTP 吗?

python 列表 id(L) 和 id(L[ :])

python - np 数组是不可变的 - "assignment destination is read-only"

java - 谷歌数据流 "No filesystem found for scheme gs"

spring - 无法在 Spring 应用程序中的 @Transactional 方法内处理 hibernate 异常

python - 在 python 中通过 ftplib 上传比手动上传花费的时间要长得多

python - ftplib MLSD 命令给出 500 Unknown command

Python 获取最近的文件FTP

Python pandas合并2个相同大小的数据框