Hi All,
I've been plaing around with the xmlrpc filter today.
I think I have everything working correctly by doing the following:
in my config/app.cfg I put:
-----------------------
[/rpc]
xmlrpc_filter.on = True
xmlrpc_filter.encoding = 'latin-1'
---------------------------
then in controller.py:
---------------------------
class RPCTest(controllers.Controller):
@expose()
def count(self,num):
return num+1
class Root(controllers.RootController):
rpc = RPCTest()
---------------------------
My client code is as follows:
---------------------------
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:8080/rpc/',verbose=1)
s.count(1)
---------------------------
Which returns the following error:
--------------------------
"<?xml version='1.0'?>
<methodResponse>
<fault>
<value><struct>
<member>
<name>faultCode</name>
<value><int>1</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Method RPCTest.count() returned unexpected output.
Output should be of type basestring, dict or
generator.</string></value>
</member>
</struct></value>
</fault>
</methodResponse>"
----------------------
I always get this error, except when i return a string from the count
method, then all is fine.
If I use "_cpFilterList =
[cherrypy.lib.filter.xmlrpcfilter.XmlRpcFilter()]" which some docs
suggest, everything freezes, and I get a timeout error, so I think this
probably should not be used anymore in recent versions.
The cherrypy documentation from
http://www.turbogears.org/docs/api/cherrypy.lib.filter.xmlrpcfilter.XmlRpcFilter-class.html
says:
--------------------
cherrypy.response.body must be a python source string;
this string is 'eval'ed to return the results. This will be
resolved in the future.
--------------------
That sounds like a bit of a hack, however it should mean that if i
return str(num+1), it should be eval'd back to an int, and then get
xml-encoded. This does not happen, it looks like the whole eval step
has been removed.
I understand that an exposed method can only return a string or a dict,
not an int or a list. That seems to be the root of the problem. Does
anyone have some ideas/workarounds for this?
I'm using turbogears 0.9a4 on linux,
Thanx,
Jasp.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---