Help with "hello world" FCGI

software development


I am having trouble getting a basic Python Fast-CGI script working, and hope I can get a little help. I did the following:

  • Downloaded the script and put it in /home/tiddman/packages/lib/python2.3/site-packages.

  • Made sure that this:

is in my .bashrc and .bashrc_profile

  • Say that my domain name is “”. I put the following script in ~/

[code]#!/usr/bin/env python
import os
print “PYTHONPATH=”,os.environ.get(“PYTHONPATH”)
def myapp(environ, start_response):
start_response(‘200 OK’, [(‘Content-Type’, ‘text/plain’)])
return [‘Hello World!\n’]

if name == ‘main’:
from fcgi import WSGIServer
WSGIServer(myapp).run()[/code]- Set execute permissions with “chmod 755

  • Tested the script from the command line, and got this:

[code]PYTHONPATH= /home/tiddman/packages/lib/python2.3/site-packages
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/plain
Content-Length: 13

Hello World![/code]- Despite the complaints from WSGIServer, I think this basically works.

  • Now I tried to invoke this script by hitting this URL: browser hangs for 60 seconds and times out, and I see this error message:

[Thu Apr 26 15:02:39 2007] [error] [client x.x.x.x] FastCGI: comm with (dynamic) server "/home/tiddman/" aborted: (first read) idle timeout (60 sec) [Thu Apr 26 15:02:39 2007] [error] [client x.x.x.x] FastCGI: incomplete headers (0 bytes) received from server "/home/tiddman/"- I am pretty sure the problem is that the script’s environment does not have PYTHONPATH set correctly. To check this, I wrote the following script

#!/usr/bin/python import os print "Content-Type: text/plain\n" print "PYTHONPATH=",os.environ.get("PYTHONPATH")When I run this from the command line I get:

[code]Content-Type: text/plain

PYTHONPATH= /home/tiddman/packages/lib/python2.3/site-packages[/code]When I execute this by hitting the url, I get this:

PYTHONPATH= NoneI have asked Dreamhost technical support about this in as many different ways as I can think of (nicely of course) and they won’t provide any help because they say that “they don’t provide help debugging scripts”.

One thing they suggested was adding parameters to my script using env, like this:

#!/usr/bin/env PYTHONPATH=... pythonI tried that, but the script hangs when run from the command line, and gives the same error as above when invoked from the web browser

I have been banging my head against this for about a week and can’t find a solution. Surely I am doing something terribly stupid, since this is the simplest of atomic functionality. Getting the most basic “hello world” FCGI application should not be this hard.

Any assistance most welcome!



I’ve this problem with python too .
After tryind various methods, I found this working for me.

  1. Install flup(
  • copy flup folder in your /home/yourdomain/plib
  1. Test code
    ------------- Start Code -------------------------------
    import sys
    def myapp(envirom, start_response):
    start_response(‘200 OK’, [(‘Content-Type’, ‘text/plain’)])
    return [‘Hello World!xx\n’]

if name == “main”:
from flup.server.fcgi_fork import WSGIServer
------------- End Code -------------------------------
3. You can see this working url at

Hope this help