[mod_python] bug in apache.build_cgi_env

Gregory (Grisha) Trubetskoy grisha at modpython.org
Sun Oct 17 20:51:11 EDT 2004


This gives you an idea of how much that function is being used :-)

My guess is that in some prior versions of Python length on None used to 
be 0.

I'll add this to the list of things to be fixed, thanks!

Grisha


On Wed, 13 Oct 2004, Robert Brewer wrote:

> Hi,
>
> 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
>    http://hoohoo.ncsa.uiuc.edu/cgi/env.html
>    """
>
>    req.add_common_vars()
>    env = req.subprocess_env.copy()
>
>    if len(req.path_info) > 0:
>        env["SCRIPT_NAME"] = req.uri[:-len(req.path_info)]
>    else:
>        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)]
>    else:
>        env["SCRIPT_NAME"] = req.uri
>
>
> Thanks for your time,
>
>
> Robert Brewer
> MIS
> Amor Ministries
> fumanchu at amor.org
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list