waiting for request using BaseRequestHandler

bromden bromden at gazeta.pl.no.spam
Thu Oct 16 02:44:42 EDT 2003


please read the docstring of the class BaseHTTPRequestHandler

 >>> import BaseHTTPServer
 >>> print BaseHTTPServer.BaseHTTPRequestHandler.__doc__

normally you should subclass BaseHTTPRequestHandler and override
methods do_GET(), do_POST() and so on, which are handling specific
HTTP commands,
the info about a request being processed is stored in the class
members described in the docstring, specifically the path is
in  (guess) "path",
moreover, you shouldn't assemble response header yourself,
use the methods send_response(), send_error() instead,

so what you should do is something like

class ListHandler(BaseHTTPServer.BaseHTTPRequestHandler):

def do_GET(self):
     if (self.path) == '/Peter':
         data = self.makeList()
         self.send_response(200)
         self.send_header('Content-Length', str(len(data)))
         self.end_headers()
         self.wfile.write(data)
         ....
     else:
         ....

-- 
bromden[at]gazeta.pl





More information about the Python-list mailing list