A Simple Server to Capture Single Short Requests

C

Craig Edgmon

I am working through Steve Holdens book on Python Web Development and
this may seem like an obvious question, but my error states that
MyRequestHandler is not defined. Any ideas on this?

import SocketServer

class MyRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
print "_____________________________"
print "From: ", self.client_address
print "_____________________________"
input = self.request.recv(10240)
print input.replace('\r', '')
print "_____________________________"
self.request.send("HTTP/1.1 200 OK\r\n")
self.request.send("Content-Type: text/html\n\n")
self.request.send("<HTML><BODY><H2>Hello!</H2></BODY></HTML>")
self.request.close()

myServer = SocketServer.TCPServer(('', 8080), MyRequestHandler)
myServer.handle_request()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top