0
class WebServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):

    # Works with basehttphandler
    do_get(self):
        if 'home' in self.path:
            <do something here>

# "Working" Method is commented out. The problem I'm having is being unable to
# handle requests like GET, POST, etc with CGIHTTPRequestHandler.:
#
#DoIT=BaseHTTPServer.BaseHTTPRequestHandler((SERVER_ADDRESS,PORT),WebServer)

DoIt=webserver((SERVER_ADDRESS,PORT),CGIHTTPServer.CGIHTTPRequestHandler)
DoIT.serve_forever()

This works with basehttprequesthandler, not with cgihttprequesthandler. I need a way to manage both 'types'(using both libraries?) of requests if that's even feasible. Thanks in advance.

  • When something doesn't work, try to give some details. Do you get an error message? Does it not do something you were expecting? – Thomas K Nov 18 '11 at 18:09
  • essentially what i'm trying to do is manage the GET requests and other HTTP request methods. using BaseHTTPServer, the "do_GET(self)" works. as soon as i use CGIHTTPRequestHandler that is no longer an option. I don't receive any errors, it simply stops working. Since I need to be able to use cgi, just using basehttpserver is not project scalable. I need to be able to handle "do_GET(self)" type functions with the CGIHTTPServer, basically. Sorry about any confusion. I'm not so well with explanations. – user1054340 Nov 18 '11 at 20:58

1 Answers1

-1

Try something like this:

import BaseHTTPServer
import CGIHTTPServer

server = BaseHTTPServer.HTTPServer
server_address = ("", 8888)

class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler):
    def do_GET(self):
        #do something

    def do_POST(self):
        #do something

httpd = server(server_address, MyHandler)
httpd.serve_forever()
Prashant Borde
  • 1,058
  • 10
  • 21