How to catch this Python exception: error: [Errno 10054] An existing connection was forcibly closed by the remote host

后端 未结 3 968
旧时难觅i
旧时难觅i 2020-12-29 10:22

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?

3条回答
  •  情书的邮戳
    2020-12-29 11:12

    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
    

提交回复
热议问题