How to pass informations from mod_python to CGI scripts

67 views Asked by At

I use mod_python for my own custom authentication mechanism like this:

# apache/conf/conf.d/mod_python.conf

<Directory some/path>
    PythonAccessHandler myhandler::myhandler
    Options +ExecCGI
    AddHandler cgi-script .cgi
</Directory>

-

# myhandler.py

from mod_python import apache

def myhandler(req):
    if check(req):
        return apache.DECLINED
    else:
        return apache.HTTP_UNAUTHORIZED

def check(req):
    from random import random
    return random() >= 0.5

and would like to have some CGI scripts that will be executed when myhandler declines.

#!/bin/bash
# test.cgi

echo Content-type: text/plain
echo
echo "Hello!"

This configuration works fine, but in addition to this, I would like to pass sevral information from mod_python to the CGI scripts just like this:

# myhandler.py

def myhandler(req):   
    if check(req):
        import sys
        req.subprocess_env['python_version'] = repr(sys.version_info)
        return apache.DECLINED
    else:
        return apache.HTTP_UNAUTHORIZED

-

#!/bin/bash
# test2.cgi

echo Content-type: text/plain
echo
echo "python version = $python_version"

However, this configuration does not work. The values passed to req.subprocess_env are discarded in the CGI scripts.

Is there any way to pass information from mod_python to CGI script?

Any help would be appreciated.

1

There are 1 answers

0
Michitaro Koike On

The way I suggested works as expected in apache 2.4 but not in 2.2