Mod-python problem

Bob Parnes bp at sam.localdomain
Thu Feb 28 21:13:41 EST 2002


On 28 Feb 2002 07:34:08 -0800, Alan Kennedy <alanmk at hotmail.com> wrote:
>bp at sam.localdomain (Bob Parnes) wrote in message 
>> Just in case I am missing something obvious, the following 
>> is my test code, for a linux system:
>
>
>So, the corrected version, which works for me, is as follows
>
># Script starts here
>
>from mod_python import util
>from mod_python import apache
>
>class clTest:
>    def cltest(self, req, formDict):
>        res = '<html><head></head><body>'
>        res += '<table align=center>'
>        res += '<TR><TH colspan=2>Welcome to the \
>            mod-python class test'
>        res += '<TR><TD colspan=2>keys: %s' \
>		    % formDict.keys()
>        res += '<form method=post>'
>        res += '<TR><TD>Name <TD><input type=text \
>            name="name">'
>        res += '<TR><TD>Phone <TD><input type=text \
>            name="phone">'
>        res += '<TR><TD colspan=2 align=center> \
>            <input type=submit name=submit>'
>        res += '</form></table></body></html>'
>        return res
>
>def handler(req):
>    formDict = util.FieldStorage(req)
>    cl = clTest()
>    req.content_type = "text/html"
>    req.send_http_header()
>    req.write(cl.cltest(req, formDict))
>    return apache.OK
>    
># Script ends here
>
>Hope that works.

Al,

Thanks for the detailed response. Your comments were easy to understand. 
Furthermore your corrected version works for me too, under the conditions 
you had assumed. I learned a lot from this.

The only trouble is that I had forgotten about my httpd.conf file. The 
relevant lines are:

<Directory /var/www/modPython/test>
  AddHandler python-program .py
  PythonHandler mod_python.publisher
</Directory>

This was the reason I used main() instead of handler(); in the url window I 
typed in "test.py/main" and got the table but no response from FieldStorage().
When I changed the third line to "PythonHandler test", your corrected version 
works. When I do not change the line and type 'test.py/handler' in the url 
window, the browser renders a table but also additional lines showing an 
error. The source of the rendered display is as follows:
---------------------------------------------------------------------

<html><head></head><body><table align=center><TR><TH colspan=2>Welcome to the 	
		mod-python class test<TR><TD colspan=2>keys: []<form 
method=post><TR><TD>Name <TD><input type=text 
			name='name'><TR><TD>Phone <TD><input type=text 
			name='phone'><TR><TD colspan=2 align=center>
			<input type=submit 
name=submit></form></table></body></html>HTTP/1.1 200 OK
Date: Fri, 01 Mar 2002 01:34:22 GMT
Server: Apache/1.3.23 (Unix) Debian GNU/Linux mod_python/2.7.6 Python/2.1.2
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,
 bp at sam 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>
</BODY></HTML>
-------------------------------------------------------------------------

No lines concerning the error were printed in the error log. But it seems to
me that, as a result of the error, the http header and "OK" from 
"return apache.OK" were simply displayed as text. 

Are publisher and FieldStorage() incompatible, or am I misusing them? Knowing 
what I know now, I can probably get along without publisher, but I am 
accustomed to placing several scripts in one directory.

Bob

-- 
Bob Parnes
rparnes at megalink.net



More information about the Python-list mailing list