[Twisted-Python] adbapi results through xmlrpc
![](https://secure.gravatar.com/avatar/0e899fd4b55d0094384e37ce99af6565.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Wed, 2004-03-31 at 16:08, Zach Thompson wrote:
I can understand that xmlrpc needs to serialize the Deferred object to send it through http.
Actually, Deferreds are handled transparently. The issue is probably that your database adapter returns objects xmlrpc can't handle (e.g. things that look like lists but aren't, etc..) So you want to addCallback something that converts the objects. -- Itamar Shtull-Trauring http://itamarst.org
![](https://secure.gravatar.com/avatar/fdaa75758deee2fce225653d708b9557.jpg?s=120&d=mm&r=g)
Zach Thompson [Wed, Mar 31, 2004 at 01:08:09PM -0800]:
return lambda results: int(result[0]) Some DBAPI modules return actually objects of various types sometimes...
Failure: xmlrpclib.Fault: <Fault 8002: "can't serialize output">
... which are not serializable. -- Michal Pasternak :: http://pasternak.w.lub.pl :: http://winsrc.sf.net
![](https://secure.gravatar.com/avatar/0e899fd4b55d0094384e37ce99af6565.jpg?s=120&d=mm&r=g)
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:
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Wed, 2004-03-31 at 16:08, Zach Thompson wrote:
I can understand that xmlrpc needs to serialize the Deferred object to send it through http.
Actually, Deferreds are handled transparently. The issue is probably that your database adapter returns objects xmlrpc can't handle (e.g. things that look like lists but aren't, etc..) So you want to addCallback something that converts the objects. -- Itamar Shtull-Trauring http://itamarst.org
![](https://secure.gravatar.com/avatar/fdaa75758deee2fce225653d708b9557.jpg?s=120&d=mm&r=g)
Zach Thompson [Wed, Mar 31, 2004 at 01:08:09PM -0800]:
return lambda results: int(result[0]) Some DBAPI modules return actually objects of various types sometimes...
Failure: xmlrpclib.Fault: <Fault 8002: "can't serialize output">
... which are not serializable. -- Michal Pasternak :: http://pasternak.w.lub.pl :: http://winsrc.sf.net
![](https://secure.gravatar.com/avatar/0e899fd4b55d0094384e37ce99af6565.jpg?s=120&d=mm&r=g)
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:
participants (3)
-
Itamar Shtull-Trauring
-
Michal Pasternak
-
Zach Thompson