如何捕获此Python异常:错误:[Errno 10054]远程主机强制关闭现有连接 [英] How to catch this Python exception: error: [Errno 10054] An existing connection was forcibly closed by the remote host

查看:2883
本文介绍了如何捕获此Python异常:错误:[Errno 10054]远程主机强制关闭现有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Python 2.7中捕获这个特殊的异常(只有这个异常),但是我似乎找不到异常类的文档。有没有一个?

I am trying to catch this particular exception (and only this exception) in Python 2.7, but I can't seem to find documentation on the exception class. Is there one?

[Errno 10054] An existing connection was forcibly closed by the remote host

我的代码到目前为止:

try:
  # Deleting filename
  self.ftp.delete(filename)
  return True
except (error_reply, error_perm, error_temp):
  return False
except # ?? What goes here for Errno 10054 ??
  reconnect()
  retry_action()


推荐答案

错误类型为socket.error,文档为此处
尝试改装你的代码:

The error type is socket.error, the documentation is here. Try modiffying your code like this:

import socket
import errno  

try:
    Deleting filename
    self.ftp.delete(filename)
    return True
except (error_reply, error_perm, error_temp):
    return False
except socket.error as error:
    if error.errno == errno.WSAECONNRESET:
        reconnect()
        retry_action()
    else:
        raise

这篇关于如何捕获此Python异常:错误:[Errno 10054]远程主机强制关闭现有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆