Hi,
I'm trying to build a web server in Python, and here is what I have so far:
Code:
from http.server import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def _writeheaders(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_HEAD(self):
self._writeheaders()
def do_GET(self):
self._writeheaders()
self.wfile.write("""<HTML>
<HEAD><TITLE>Sample title</TITLE></HEAD>
<BODY>sample text</BODY>
</HTML>""")
serveraddr = ('', 8080)
srvr = HTTPServer(serveraddr, RequestHandler)
srvr.serve_forever()
I do not get any errors, however when it runs the shell opens and nothing happens.
What changes to this code would I do to make it work?
Thanks.