Creating an HTTP Server to Handle GET Requests : Web Server : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » Web Server »

 

Creating an HTTP Server to Handle GET Requests


import BaseHTTPServer, cgi
import os

class httpServHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
     if self.path.find('?'!= -1:
         self.path, self.query_string = self.path.split('?'1)
     else:
         self.query_string = ''
     self.send_response(200)
     self.send_header('Content-type','text/html')
     self.end_headers()
     self.globals = dict(cgi.parse_qsl(self.query_string))
     sys.stdout = self.wfile
     self.wfile.write("<H2>Handle Get</H2><P>")
     self.wfile.write("<LI>Executing <B>%s</B>" (self.path))
     self.wfile.write("<LI>With Globals<B>%s</B><HR>" (self.globals))
     execfile(self.path, self.globals)

os.chdir('/myTest')
serv = BaseHTTPServer.HTTPServer(servAddr, httpServHandler)
serv.serve_forever()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» Web Server