Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-16-2007, 03:38 PM   #1
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
mod_python - forms not working with publisher - Connection refused

I'm trying to run the example from the mod_python website & it doesn't work. That said, I can get python scripts to work with the web, just not forms. Maybe I'm doing something wrong?

here's the code:
      Please provide feedback below:
  <form action="" 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">

import smtplib

WEBMASTER = "webmaster"   # webmaster e-mail
SMTP_SERVER = "localhost" # 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:


Thank You,


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

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

    # provide feedback to the user
    s = """\

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

</html>""" % name

    return s
with this apache config:
<Directory "/local/htdocs/python"> 
   AddHandler mod_python .py
   PythonHandler mod_python.publisher
   PythonDebug On 
makes this error:

ProcessId:      6764
Interpreter:    ''

ServerName:     ''
DocumentRoot:   '/local/htdocs'

URI:            '/python/'
Location:       None
Directory:      '/local/htdocs/python/'
Filename:       '/local/htdocs/python/'
PathInfo:       '/email'

Phase:          'PythonHandler'
Handler:        'mod_python.publisher'

Traceback (most recent call last):

  File "/local/lib/python2.5/site-packages/mod_python/", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/local/lib/python2.5/site-packages/mod_python/", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/local/lib/python2.5/site-packages/mod_python/", line 1128, in _execute_target
    result = object(arg)

  File "/local/lib/python2.5/site-packages/mod_python/", line 213, in handler
    published = publish_object(req, object)

  File "/local/lib/python2.5/site-packages/mod_python/", line 425, in publish_object
    return publish_object(req,util.apply_fs_data(object, req.form, req=req))

  File "/local/lib/python2.5/site-packages/mod_python/", line 554, in apply_fs_data
    return object(**args)

  File "/local/htdocs/python/", line 30, in email
    conn = smtplib.SMTP(SMTP_SERVER)

  File "/local/lib/python2.5/", line 244, in __init__
    (code, msg) = self.connect(host, port)

  File "/local/lib/python2.5/", line 310, in connect
    raise socket.error, msg

error: (111, 'Connection refused')


Accessed:       Tue Oct 16 12:17:36 2007
Generation:     3

_mp_441c039e42e284614105ccd2ecb3c1f7 {
  FileName:     '/local/htdocs/python/'
  Instance:     1 [IMPORT]
  Generation:   4
  Modified:     Mon Oct 15 11:20:38 2007
  Imported:     Tue Oct 16 12:17:36 2007
any ideas?
Old 10-16-2007, 03:44 PM   #2
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Originally Posted by BrianK View Post
I'm trying to run the example...
of course, after banging my head on this for long enough to post a question, not 5 minutes later, I've found the solution. The sending mail part was the problem. Don't know why they would put that in their simple example.

Oh well.. If anyone else comes up with this same problem, just comment out the lines that start with "conn"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync ,rcp not working-Connection refused! jimmyjiang Linux - Networking 2 09-17-2008 05:34 AM
rdesktop stopped working - ERROR: connect: Connection refused donraja Linux - Software 6 02-26-2008 08:39 PM
apache2 mod_python.publisher upload problem gd2shoe Linux - Server 0 06-28-2007 11:32 PM
KMLDonkey isn't working - "Connection Refused" machron1 SUSE / openSUSE 8 03-15-2005 05:41 PM
Wine not working. Xlib: connection to ":0.0" refused by server Xerop Linux - General 1 02-18-2004 10:37 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration