[mod_python] How to handle multiple .py files using Apache 1.3.x and mod_python 2.7

Eustaquio Rangel de Oliveira Jr. eustaquiorangel at yahoo.com
Thu Apr 15 13:33:39 EST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jorey Bump wrote:

|Assuming you're using publisher and your DocumentRoot is /var/www/html,
|you can do this:

|  <Directory /var/www/html>
|    AddHandler python-program .py
|    PythonHandler mod_python.publisher
|    PythonDebug On
|  </Directory>

|That would allow you to use .py files almost anywhere. Specify a
|subdirectory if you want to limit it. There are no conflicts with
|mod_php.

Hey, thanks for your answer. I did this, and when I try to run test.py:

from mod_python import apache

def handler(req):
	req.content_type = "text/plain"
	req.send_http_header()
	req.write("Hello, world!<br>")
	r = range(0,10)
	for n in r:
		req.write(str(n)+"<br>")
	return apache.OK

I got a:

Not Found
The requested URL /test.py was not found on this server.
Apache/1.3.29 Server at taq.localhost Port 80

But if a change test.py to:

from mod_python import apache

def say(req,what="NOTHING"):
	return "I'm saying %s" % what

def handler(req):
	req.content_type = "text/plain"
	req.send_http_header()
	req.write("Hello, world!<br>")
	r = range(0,10)
	for n in r:
		req.write(str(n)+"<br>")
	return apache.OK

and use the URL:
http://localhost/test.py/say?what=hello

I get this:
I'm saying hello

But if I use the URL:
http://localhost/test.py/handler

I get:

Hello,
world!<br>0<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>HTTP/1.1 200 OK
Date: Thu, 15 Apr 2004 16:22:58 GMT
Server: Apache/1.3.29 (Unix) mod_python/2.7.10 Python/2.2.2 PHP/4.3.4
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>200 OK</TITLE>
</HEAD><BODY>
<H1>OK</H1>
The server encountered an internal error or
misconfiguration and was unable to complete
your request.<P>
Please contact the server administrator,
~ taquinho at localhost.localdomain and inform them of the time the error
occurred,
and anything you might have done that may have
caused the error.<P>
More information about this error may be available
in the server error log.<P>
<HR>
<ADDRESS>Apache/1.3.29 Server at taq.localhost Port 80</ADDRESS>
</BODY></HTML>

In this case, I can't expect that the handler will process my request,
and must use a internal function on the URL and send the
"<html><head><body> etc" on the return string of that function?

I have Python 2.2.2-26 here and
LoadModule python_module libexec/mod_python.so on the httpd.conf file.

Thanks again,

- --
~    .--.     TaQ (Eustáquio Rangel)                  ((__-^^-,-^^-__))
~   |o_o |    Usuário registrado GNU/Linux no. 224050  `-_---' `---_-'
~   |:_/ |    email  : eustaquiorangel at yahoo.com        `--|o` 'o|--'
~  //   \ \   URL    : http://beam.to/taq                  \  `  /
~ (|     | )  ICQ    : 110103942                            ): :(
/'\_   _/`\  PGP key: 0x784988BB                           :o_o:
\___)=(___/  Eu gosto de GNU/Linux, e vc ? ;)               "-"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAfrlib6UiZnhJiLsRAv+SAJ9sz1IMAbgPCgalSPZfIdbjklkTuwCgmejL
wATL5p7vI7kyAJTGAfzVhQE=
=iFbN
-----END PGP SIGNATURE-----


More information about the Mod_python mailing list