title: How to execute a python cgi-script under Linux
body: <p>I have a python cgi script which executed fine on a Windows machine simply by starting CGIHTTPServer in the console, opening the html page to pass the data to the script and submitting the data.<br>
  I now need to do this under Linux but this is proving more difficult.  Some web searching has given this script to start the server (I've put in 8000 as the original 80 didn't work)</p>
  
  <pre><code> import os  
   import BaseHTTPServer, CGIHTTPServer  
   serverAddr = ("", 8000)  
   os.chdir("/home/apannife/www")  
   serv = BaseHTTPServer.HTTPServer( \  
       serverAddr, CGIHTTPServer.CGIHTTPRequestHandler)  
   serv.serve_forever()  
  </code></pre>
  
  <p>the html.  </p>
  
  <pre><code>&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;
  
  Test
  
  &lt;/TITLE&gt;
  
  &lt;/HEAD&gt;
  
  &lt;BODY&gt;
  
  &lt;B&gt;  Filename &lt;/B&gt;
  
  &lt;FORM METHOD=post ACTION="cgi-bin/docking_cgi.py" ENCTYPE="multipart/form-data"&gt;
  
  &lt;INPUT Type="file" NAME="upfile" SIZE=45&gt;&lt;BR&gt;
  
  &lt;P&gt;&lt;INPUT TYPE=submit&gt;&lt;/FORM&gt;
  
  
  
  &lt;/BODY&gt;&lt;/HTML&gt;
  </code></pre>
  
  <p>and the first part of the cgi.  </p>
  
  <pre><code>#!/usr/bin/env python
  
  import cgi
  
  from cgi import FieldStorage
  
  
  reshtml = '''Content-Type: text/html\n
  
  &lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;
  
  DEMO
  
  &lt;/TITLE&gt;&lt;/HEAD&gt;
  
  &lt;BODY&gt;&lt;H3&gt; OUTPUT SENT TO %s %s &lt;/H3&gt;
  
  &lt;/BODY&gt;&lt;/HTML&gt;'''
  form = cgi.FieldStorage()
  
  upfile = form['upfile']
  </code></pre>
  
  <p>However submitting the data just returns the text of the cgi script and doesn't run it.  I've chmod-ded 775 everything in sight and it looks like the server is not automagically understanding that I want it to execute the script.  How do I make it do so?
  thanks.</p>