title: Fetching HTTP GET variables in Python
body: <p>I'm trying to set up a HTTP server in a Python script. So far I got the server it self to work, with a code similar to the below, from <a href="https://stackoverflow.com/questions/2617615/slow-python-http-server-on-localhost">here</a>.</p>
  
  <pre><code>from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  
  class MyHandler(BaseHTTPRequestHandler):
      def do_GET(self):
          print("Just received a GET request")
          self.send_response(200)
          self.send_header("Content-type", "text/html")
          self.end_headers()
  
          self.wfile.write('Hello world')
  
          return
  
      def log_request(self, code=None, size=None):
          print('Request')
  
      def log_message(self, format, *args):
          print('Message')
  
  if __name__ == "__main__":
      try:
          server = HTTPServer(('localhost', 80), MyHandler)
          print('Started http server')
          server.serve_forever()
      except KeyboardInterrupt:
          print('^C received, shutting down server')
          server.socket.close()
  </code></pre>
  
  <p>However, I need to get variables from the GET request, so if <code>server.py?var1=hi</code> is requested, I need the Python code to put <code>var1</code> into a Python variable and process it (like print it). How would I go about this? Might be a simple question to you Python pros, but this Python beginner doesn't know what to do! Thanks in advance!</p>