[mod_python] problem creating an instance and debugging

Daniel Rubin dlrubin at yahoo.com
Thu Jul 3 11:41:10 EST 2003

Here's the xmlrpc.py code. My client code is calling
the "evaluate" function via a call like this:
server = xmlrpclib.ServerProxy(myURI)

If I put the "return data" statement right before the
"model=Model()" statement, then things work fine. If I
put the return statement after it, then I get the
stack dump I showed you earlier. The code never jupmps
to the except: clause, and no errors are being written
to the apache logs (and my conf file is set to record
everything with no virtual hosts).

from mod_python import apache
import xmlrpclib

def evaluate(data):
     import MyTools import Model
          model = Model()  <--an error happens here
          return data
'w').write("RUNNING ON %s" % findings)
          import traceback

def handler(req):
    import sys
    module = sys.modules[__name__]

    # Load the method and arguments from the client.
    content = req.read()

    # xmlrpclib fails if there are characters with
ASCII code >= 128.
    # Thus, change anything greater than that to a
    table = ''.join(map(chr, range(128))) + " "*128
    content = content.translate(table)
    args, method_name = xmlrpclib.loads(content)

    # Call the method.
    if hasattr(module, method_name):
            retval = getattr(module,
        except Exception, x:
            retval = xmlrpclib.Fault(
                0, "Exception (%s) raised: %s" %
(Exception.__name__, str(x)))
        except x:
            retval = xmlrpclib.Fault(
                0, "General exception raised: %s" %
        retval = xmlrpclib.Fault(
            0, "This server does not provide: '%s'" %

    # Marshal the return value and write the results
back to the
    # client.
    req.content_type = "text/xml"
    marshalled = xmlrpclib.dumps((retval,),
    return apache.OK

--- "Gregory (Grisha) Trubetskoy"
<grisha at modpython.org> wrote:
> On Thu, 3 Jul 2003, Daniel Rubin wrote:
> > An error is happening in the xmlrpc.py program,
> and this isn't making
> > it's own stack dump or errors written to the
> apache logs on the server.
> > So I can't debug what the nature of the error that
> is happening in the
> > remotely called function.
> So, tell me if I understand this correctly (I'm not
> familiar with
> xmlrpc.py) -
> Xmlrpc.py is a CGI script which reports its errors
> by writing them to
> stderr. Something happens when you run it under
> mod_python, and you don't
> know what it is because stderr goes nowhere.
> As far as I know, stderr output may end up in your
> error log, but I don't
> think that's guaranteed and may be dependent on how
> your httpd was
> compiled.  I think there is really no solution to
> this other than to tweak
> xmlrpc into raising its exception or using
> mod_python's log_error to
> report it.
> HTH,
> Grisha

Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

More information about the Mod_python mailing list