1

I have installed Python and configured in apache. I created a Python web file and open this in browser, I get an error. But the same code working in command-line. I hope the problem is from my apache configuration.

This is the error message.

MOD_PYTHON ERROR

ProcessId:      6368
Interpreter:    'localhost'

ServerName:     'localhost'
DocumentRoot:   '/var/www'

URI:            '/python_test/hello_world.py'
Location:       None
Directory:      '/var/www/'
Filename:       '/var/www/python_test/hello_world.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'mod_python.py'

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 304, in import_module
    return __import__(module_name, {}, {}, ['*'])

ImportError: No module named py

My Python code is :

print "Hello world!"


My httpd.conf file is :

ServerName localhost
<Directory /var/www/>
        Options Indexes FollowSymlinks MultiViews
        AllowOverride AuthConfig
        order allow,deny
        allow from all

        AddHandler mod_python .py
        PythonHandler mod_python.py
        PythonDebug On

</Directory>
1
  • 1
    Why oh why do you still use the long dead mod_python? Commented Apr 30, 2013 at 15:11

3 Answers 3

3

AddHandler requires additional parameters and you basically provide it with the python extension .py. Then you provide the name of the Python file to the PythonHandler without the extension.

AddHandler cgi-script .py
PythonHandler mod_python
PythonDebug On
Sign up to request clarification or add additional context in comments.

Comments

1

There appears to be a typo in your httpd.conf AddHandler mod_python .py

Because of the space it is looking for two modules mod_python and py

1 Comment

Thanks for your reply, when I removed the space and try to restart the apache. It throws following error. AddHandler requires at least two arguments, a handler name followed by one or more file extensions
0

you wrote :

AddHandler mod_python .py

Try to remove the blank before the .py

EDIT :

Ok, so try something like that :

SetHandler python-program
PythonHandler mod_python.py
PythonDebug On

or the following :

AddHandler mod_python py
PythonHandler mod_python.py
PythonDebug On

1 Comment

Thanks for your reply, when I removed the space and try to restart the apache. It throws following error. AddHandler requires at least two arguments, a handler name followed by one or more file extensions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.