title: Python CGI Error 500: Premature end of script headers
body: <p>I have this fairly complex python script im trying to run which imports other self-written modules and things like sqlite. When I go to run the script, I get a 500: internal server error and the log says: Premature end of script headers.</p>
  
  <p>I know this means that I probably don't have my header correctly placed/typed but I believe I do.</p>
  
  <pre><code>#!/usr/bin/env python
  
  import cgi
  import cgitb; cgitb.enable(logdir=..., format="text")
  
  print "Content-type: text/html"
  print
  </code></pre>
  
  <p>Looks right, right?</p>
  
  <p>I continue with the script and print the results at the end. All the other modules don't have the header or the hashbang, but I think that's fine.</p>
  
  <p>What could the problem be?</p>