5 from http.server import BaseHTTPRequestHandler
6 from http.server import HTTPServer
11 class HandledException(Exception):
12 """To identify Exceptions based on expected (if faulty) user behavior."""
15 class TaskHandler(BaseHTTPRequestHandler):
16 """Handles single HTTP request."""
19 """Handle any GET request."""
20 self.send_response(200)
22 html = '<html><body><p>hi there!</p></body></html>'
23 self.wfile.write(bytes(html, 'utf-8'))
28 server = HTTPServer(('localhost', HTTP_PORT), TaskHandler)
29 print(f'running at port {HTTP_PORT}')
31 server.serve_forever()
32 except KeyboardInterrupt:
33 print('aborting due to keyboard interrupt')
37 if __name__ == '__main__':
38 from sys import exit as sys_exit
41 except HandledException as e:
42 print(f'Aborting due to: {e}')