473,224 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Configuring apache to execute python scripts using mod_python handler

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.

Aug 13 '07 #1
3 4897
Hi Joe

You'd probably have better luck posting this to the mod python mailing
list. Did you name your python script mptest.py and did you remember
to restart Apache when you edited the httpd.conf file? If so then I
don't see any reason why it shouldn't work although I've never tried
mod_python under a Windows environment.

Regards

Jeffrey van Aswegen

joe jacob wrote:
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.
Aug 13 '07 #2
On Aug 13, 5:16 am, joe jacob <joejaco...@gmail.comwrote:
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.
1) In the mod_python tutorial it says:

-------
2.4 Testing

....
....

2. Add the following Apache directives, which can appear in either the
main server configuration file, or .htaccess. If you are going to be
using the .htaccess file, you will not need the <Directorytag below
(the directory then becomes the one in which the .htaccess file is
located), ***and you will need to make sure the AllowOverride
directive applicable to this directory has at least FileInfo
specified. (The default is None, which will not work.)****

<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
--------

Note the last sentence in the directions above. I explain what is
needed for that part at the link in (2) below. Also note the
directory listed in the opening <Directorytag:

/some/directory/htdocs/test

That specifies a sub directory of htdocs. That's because the htdocs
directory has its own <Directorytag in httpd.conf, which specifies
the things you can to with it. If you look around in httpd.conf, you
will see the <Directorytag that applies to htdocs. Mine looks like
this:

<Directory "/Library/Apache2/htdocs">
....
....
<Directory>

The mod_python Testing tutorial wants you to create your own sub
directory in htdocs, so that you can specify your own rules for that
directory. You're probably getting errors because you have two
<Directorytags in your httpd.conf file for the htdocs directory, and
the second tag is overwriting the first one.
2) You can see the latter part of this thread for what I did to get
mptest.py to work:

http://groups.google.com/group/comp....2645ec03370fb2
3) I put any <Directorytags I added to httpd.conf below the first
<Directorytag in http.conf, which is this one:

<Directory "/Library/Apache2/htdocs">

so that the ones lower down in the file will override the previous
tags if there is a conflict.

Aug 13 '07 #3
On Aug 13, 9:44 pm, 7stud <bbxx789_0...@yahoo.comwrote:
On Aug 13, 5:16 am, joe jacob <joejaco...@gmail.comwrote:
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.

1) In the mod_python tutorial it says:

-------
2.4 Testing

...
...

2. Add the following Apache directives, which can appear in either the
main server configuration file, or .htaccess. If you are going to be
using the .htaccess file, you will not need the <Directorytag below
(the directory then becomes the one in which the .htaccess file is
located), ***and you will need to make sure the AllowOverride
directive applicable to this directory has at least FileInfo
specified. (The default is None, which will not work.)****

<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
--------

Note the last sentence in the directions above. I explain what is
needed for that part at the link in (2) below. Also note the
directory listed in the opening <Directorytag:

/some/directory/htdocs/test

That specifies a sub directory of htdocs. That's because the htdocs
directory has its own <Directorytag in httpd.conf, which specifies
the things you can to with it. If you look around in httpd.conf, you
will see the <Directorytag that applies to htdocs. Mine looks like
this:

<Directory "/Library/Apache2/htdocs">
...
...
<Directory>

The mod_python Testing tutorial wants you to create your own sub
directory in htdocs, so that you can specify your own rules for that
directory. You're probably getting errors because you have two
<Directorytags in your httpd.conf file for the htdocs directory, and
the second tag is overwriting the first one.

2) You can see the latter part of this thread for what I did to get
mptest.py to work:

http://groups.google.com/group/comp....thread/thread/...

3) I put any <Directorytags I added to httpd.conf below the first
<Directorytag in http.conf, which is this one:

<Directory "/Library/Apache2/htdocs">

so that the ones lower down in the file will override the previous
tags if there is a conflict.
Thank you very much I got it working.

Aug 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rolfe | last post by:
Has anyone had success getting mod_python to run on Apache on Win2K? I'm writing up instructions on how to do this and need your help. When completed, the instructions at the mod_python website and...
1
by: Rolfe | last post by:
Hi, I struggled, and got mod_python running on Apache/Win2k. Follow these instructions verbatim and you shouldn't have any trouble. These instructions are based on...
6
by: Piet | last post by:
Hi there, I cannot install mod_python v3.1.3 on either Win2k/ActivePython 2.3.2 or WinMe/Python 2.3.4. When I run the Windows installer, I get the following error message: Traceback (most recent...
2
by: Ian Pellew | last post by:
Hi all; Am I correct in thinking that Mod_Python simply executes Python scripts from the server side using an internal Apache python engine? Can a web page have Python script embedded in it...
2
by: digidalmation | last post by:
Hello all. I've been trying to get my linux server to run mod_python. It's a Mandrake 10 linux box, and apache/mod_python are installed from rpms. apache2-mod_python-2.0.48_3.1.3-1mdk...
1
by: neha | last post by:
hi, i m trying to integrate python with apache on linux.For this i m using mod_python. I dont see any problem with the versions of python,apache and mod_python i m using. the versions i m using...
5
by: msuemnig | last post by:
I've create an Ubuntu Linux box, which comes pre-installed with Python (I've added the libapache2-mod-python throught the app manager). I've created .cgi and .py simple programs in the www root...
5
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major...
2
by: m.banaouas | last post by:
I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.