Returning a deferred from the xmlrpc method will work fine -- twisted
will use the result of the deferred and not the deferred itself
when sending the return xml-rpc value.
The problem is that the result of the query is not serializable,
probably because it contains some pgsql objects somewhere.
Instead of sending the result directly, you'll probably want to
add a callback that picks the count value out of the row and column.
Also, the type of the count may not be a regular integer but some
pgsql-specific type. You'll have to do some debugging to see what's
going on.
Also, you probably don't want to create a connection pool for every
call, but if you do, don't forget to close the pool or you may end up
with lots of open connections.
dave
---- Original Message ----
From: Zach Thompson
Date: Wed 3/31/04 13:22
To: twisted-python@twistedmatrix.com
Subject: [Twisted-Python] adbapi results through xmlrpc
Hello,
I'm trying to connect 2 scripts (a server and client) xmlrpc. The
server just needs to run a db query and return the result set to the
client for display. Here's part of the server class:
def xmlrpc_get_count(self):
from twisted.enterprise import adbapi
pool = adbapi.ConnectionPool("pyPgSQL.PgSQL", database="zach")
return pool.runQuery("select count(*) from asdf")
And part of the client class:
def OnButton(self, event):
from twisted.web.xmlrpc import Proxy
proxy = Proxy("http://localhost:8080")
proxy.callRemote('get_count').addCallback(self.UpdateCount)
def UpdateCount(self, count):
self.label.SetLabel(count)
Here's what the client prints when I press the button:
Unhandled error in Deferred:
Failure: xmlrpclib.Fault: