title: Processing HTTP GET input parameter on server side in python
body: <p>I wrote a simple HTTP client and server in Python for experimenting. The first code snippet below shows how I send an HTTP GET request with a parameter named imsi. In the second code snippet I show my do_Get function implementation in the server side. My question is how I can extract the imsi parameter in the server code and send a response back to the client in order to signal the client that imsi is valid.<br>
  Thanks.</p>
  
  <p>P.S.: I verified that the client sends the request successfully.</p>
  
  <p><strong>CLIENT code snippet</strong></p>
  
  
  
  <pre><code>    params = urllib.urlencode({'imsi': str(imsi)})
      conn = httplib.HTTPConnection(host + ':' + str(port))
      #conn.set_debuglevel(1)
      conn.request("GET", "/index.htm", 'imsi=' + str(imsi))
      r = conn.getresponse()
  </code></pre>
  
  <p><strong>SERVER code snippet</strong></p>
  
  <pre><code>import sys, string, cStringIO, cgi, time, datetime
  from os import curdir, sep
  from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  
  class MyHandler(BaseHTTPRequestHandler):
  
  # I want to extract the imsi parameter here and send a success response to 
  # back to the client.
  def do_GET(self):
      try:
          if self.path.endswith(".html"):
              #self.path has /index.htm
              f = open(curdir + sep + self.path)
              self.send_response(200)
              self.send_header('Content-type','text/html')
              self.end_headers()
              self.wfile.write("&lt;h1&gt;Device Static Content&lt;/h1&gt;")
              self.wfile.write(f.read())
              f.close()
              return
          if self.path.endswith(".esp"):   #our dynamic content
              self.send_response(200)
              self.send_header('Content-type','text/html')
              self.end_headers()
              self.wfile.write("&lt;h1&gt;Dynamic Dynamic Content&lt;/h1&gt;")
              self.wfile.write("Today is the " + str(time.localtime()[7]))
              self.wfile.write(" day in the year " + str(time.localtime()[0]))
              return
  
          # The root
          self.send_response(200)
          self.send_header('Content-type','text/html')
          self.end_headers()
  
          lst = list(sys.argv[1])
          n = lst[len(lst) - 1]
          now = datetime.datetime.now()
  
          output = cStringIO.StringIO()
          output.write("&lt;html&gt;&lt;head&gt;")
          output.write("&lt;style type=\"text/css\"&gt;")
          output.write("h1 {color:blue;}")
          output.write("h2 {color:red;}")
          output.write("&lt;/style&gt;")
          output.write("&lt;h1&gt;Device #" + n + " Root Content&lt;/h1&gt;")
          output.write("&lt;h2&gt;Device Addr: " + sys.argv[1] + ":" + sys.argv[2] + "&lt;/h1&gt;")
          output.write("&lt;h2&gt;Device Time: " + now.strftime("%Y-%m-%d %H:%M:%S") + "&lt;/h2&gt;")
          output.write("&lt;/body&gt;")
          output.write("&lt;/html&gt;")
  
          self.wfile.write(output.getvalue())
  
          return
  
      except IOError:
          self.send_error(404,'File Not Found: %s' % self.path)
  </code></pre>