Handle ConnectionResetError & BrokenPipeError python http server

245 Views Asked by At

New to python serves outside of a framework. Need a simple server to run and load few pdf files forever.

Running a server in remote using http.server

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    try:
        httpd.serve_forever()
    except SocketError as e:
        if e.errno != errno.ECONNRESET:
            raise
        pass  # Don't know what to do here.

Testing at localhost is working fine. At remote, the server stops randomly. Upon checking logs I receive 2 errors frequently

Happens when client closes browser when a file is being loaded

self._sock.sendall(b)
BrokenPipeError: [Errno 32] Broken pipe

No idea what triggers this:

ConnectionResetError: [Errno 104] Connection reset by peer

How to handle these ? Do I need to add wait time or sleep time to avoid. Looking for anyhelp.

0

There are 0 best solutions below