Configuring apache to execute python scripts using mod_python handler

joe jacob joejacob21 at gmail.com
Mon Aug 13 07:16:48 EDT 2007


I configured apache to execute python scripts using mod_python
handler. I followed below mentioned steps to configure apache.

1. In http.conf I added

  <Directory "D:/softwares/Apache2.2/htdocs">
  AddHandler mod_python .py
  PythonHandler mptest
  PythonDebug On
  </Directory>

2. Then I added the line "LoadModule python_module modules/
mod_python.so" to http.conf.

Then I tried execute the python script mentioned below from browser.

from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK

Then I am getting the following error

Traceback (most recent call last):

  File "D:\softwares\Python25\Lib\site-packages\mod_python
\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "D:\softwares\Python25\Lib\site-packages\mod_python
\importer.py", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "D:\softwares\Python25\Lib\site-packages\mod_python
\importer.py", line 304, in import_module
    return __import__(module_name, {}, {}, ['*'])

ImportError: No module named mptest

I am using Apache 2.2.4, python 2.5 and mod_python-3.3.1.win32-py2.5-
Apache2.2.

I am able to execute python scripts by configuring apache to execute
the cgi scripts. But I want to execute it using mod_python as it is
faster compared to cgi mode. Someone please help me on this issue.




More information about the Python-list mailing list