[mod_python] Strangeness from the mod_python tutorial

Robert Squire rjsquire at ebi-online.com
Thu Oct 20 06:22:43 EDT 2005


Hello:
Thank you to everyone who responded to my previous posting.
Now I've hit something new.  The code that follows is taken exactly from 
the tutorial at:

http://www.modpython.org/live/current/doc-html/tut-pub.html

I expected the function email to be called with 4 parameters, the req 
object and the three inputs from the form.  However this is the error 
output from mod_python:
===========================

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.4/site-packages/mod_python/publisher.py", line 136, in handler
    result = util.apply_fs_data(object, req.form, req=req)

  File "/usr/lib/python2.4/site-packages/mod_python/util.py", line 361, in apply_fs_data
    return object(**args)


TypeError: email() takes exactly 4 non-keyword arguments (1 given)

===========================
I tried removing the req from the email parameter list and the error 
reflected the change by stating that the function takes 3 arguments and 
zero were supplied.  Is this a problem brought about by a change in 
mod_python since the tutorial was written or have I made yet another 
boneheaded error?



In the .htaccess file I have
===========================
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
===========================

The html form, form.html:
===========================
<html>
    Please provide feedback below:
<p>
<form action="form.py/email" method="POST">
    Name:    <input type="text" name="name"><br>
    Email:   <input type="text" name="email"><br>
    Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
    <input type="submit">

</form>
</html>
===========================

And the python file, form.py:
===========================
import smtplib

WEBMASTER = "webmaster"   # webmaster e-mail
SMTP_SERVER = "smtp.comcast.net" # your SMTP server

def email(req, name, email, comment):

    # make sure the user provided all the parameters
    if not (name and email and comment):
        return "A required parameter is missing, \
               please go back and correct the error"

    # create the message text
    msg = """\
From: %s
Subject: feedback
To: %s

I have the following comment:

%s

Thank You,

%s

""" % (email, WEBMASTER, comment, name)

    # send it out
    conn = smtplib.SMTP(SMTP_SERVER)
    conn.sendmail(email, [WEBMASTER], msg)
    conn.quit()

    # provide feedback to the user
    s = """\
<html>

Dear %s,<br>
Thank You for your kind comments, we
will get back to you shortly.

</html>""" % name

    return s
===========================


More information about the Mod_python mailing list