Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

My code so far:

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()
like image 784
SilentSteel Avatar asked Sep 16 '13 16:09

SilentSteel


People also ask

Can't start Server Error 10054 An existing connection was forcibly closed by the remote host?

The 10054 error is raised by the Operating System and reports that an existing connection was forcibly closed by the remote host. You should look at the workload on the execution servers at that location and check the Windows event logs for errors or other activity around the time of the failures.


1 Answers

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
like image 76
user2489743 Avatar answered Oct 06 '22 05:10

user2489743