I am trying to build a simple HTTP server and am using BaseHTTPServer in python.
When ever I try to run the code below I get a error saying that init() takes exactly 4 arguments (1 given).
I guess the problem is that the constructor in handler is overriding the BaseHTTPServer.BaseHTTPRequest
Kindly let me know where I'm going wrong
class handler(BaseHTTPServer.BaseHTTPRequestHandler):
def __init__(self,server):
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self)
self.server = server
self.port = 8080
def do_GET(self):
#perform some operation
class server():
def __init__(self):
self.port = 65531
self.host = 'localhost'
def run(self):
serverClass = BaseHTTPServer.HTTPServer
server = "xyz.c1589.com" # Some random server
h = handler(server)
server = serverClass((self.host,self.port),h)
print "Starting server!!"
try:
server.serve_forever()
except:
print "Error Creating Server"
server.server_close()
if __name__ == '__main__':
server().run()
BaseHTTPServer.BaseHTTPRequestHandler.__init__takes three arguments and the subclass requires one, so when you instantiate ahandleryou need to pass four arguments.