[mod_python] bug in apache.build_cgi_env

Robert Brewer fumanchu at amor.org
Wed Oct 13 23:02:54 EDT 2004


I'm running mod_python (3.1.3-win32) and trying to write a WSGI wrapper
for it. I figured I'd call apache.build_cgi_env to get an environ dict,
but I get the following error message:

  File "C:\Python23\lib\site-packages\mod_python\apache.py", line 541,
in build_cgi_env
    if len(req.path_info) > 0:

TypeError: len() of unsized object

I've already worked around it, but the function in question is:

def build_cgi_env(req):
    Utility function that returns a dictionary of
    CGI environment variables as described in

    env = req.subprocess_env.copy()
    if len(req.path_info) > 0:
        env["SCRIPT_NAME"] = req.uri[:-len(req.path_info)]
        env["SCRIPT_NAME"] = req.uri

    env["GATEWAY_INTERFACE"] = "Python-CGI/1.1"

    # you may want to comment this out for better security
    if req.headers_in.has_key("authorization"):
        env["HTTP_AUTHORIZATION"] = req.headers_in["authorization"]

    return env

With a little printlining, it seems my req.path_info is None, and
therefore has no length. Could we just write the following instead? It
fixed the problem for me.

    if req.path_info:
        env["SCRIPT_NAME"] = req.uri[:-len(req.path_info)]
        env["SCRIPT_NAME"] = req.uri

Thanks for your time,

Robert Brewer
Amor Ministries
fumanchu at amor.org

More information about the Mod_python mailing list