[Twisted-Python] adbapi results through xmlrpc

Zach Thompson lists at allotropic.com
Wed Mar 31 17:17:06 EST 2004


Thanks to all for the help!  Sure enough, the database adaptor was 
sending back objects (like PgInt8) that couldn't be deserialized.  I 
got it to work by changing the server code to this:

     def xmlrpc_get_count(self):
         from twisted.enterprise import adbapi
         pool = adbapi.ConnectionPool("pyPgSQL.PgSQL", database="zach")
         return pool.runQuery("select count(*) from 
asdf").addCallback(lambda results: int(results[0][0]))

I'll also be moving that ConnectionPool somewhere else so it only gets 
called once...

On Mar 31, 2004, at 1:08 PM, Zach Thompson wrote:

> 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: <Fault 8002: "can't serialize output">
>
> I can understand that xmlrpc needs to serialize the Deferred object to 
> send it through http.  I'm guessing there's a reference to the 
> ConnectionPool object contained in the Deferred, and it makes sense 
> that you wouldn't be able to serialize something like that.
>
> Any ideas?
>
> BTW, the client is running on a wxreactor, if that matters..
>
> Thanks,
> Zach
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python





More information about the Twisted-Python mailing list