0

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.

NinjaBat
  • 370
  • 4
  • 20
  • Possible duplicate [how-to-allow-or-deny-remote-connections-in-pythons-socketserver](https://stackoverflow.com/questions/49268568/how-to-allow-or-deny-remote-connections-in-pythons-socketserver) – Mohamad Ghaith Alzin Jun 05 '22 at 09:52
  • 1
    @MohamadGhaithAlzin Don't think so. I don't want to deny/allow any remote. I want to handle these occurring exceptions properly so that server doesn't die in any case. – NinjaBat Jun 05 '22 at 09:59

0 Answers0