Hello, I've a python script that works nicely from python xmlrpclib client. I'd like to use it to work from the browser, preferably using vcXMLRPC library ( www.vcdn.org/Public/XMLRPC/). py script is called "str" and is in http://localhost:8080/services . It takes one parameter s and has one line "return 'ret' + s All I get in the browser is None as the return value from the service. Any idea? --- html -- <script src="vcXMLRPC.js" type="text/javascript"></script> <script language="JavaScript" type="text/javascript"> <!-- var strService; strService = XMLRPC.getService("http://localhost:8080/"); strService.add("services.str","str") XMLRPC.onerror = function(e){ alert(e.message); return true; } var done = false; function getIt(inStr){ alert(inStr); outStr = strService.str(inStr); alert(outStr); return (outStr); } //--> </script> TIA S Babu
Hi I had the same problem last week. vcXMLRPC puts strings into a CDATA section, which seems to be a problem. I modified their String.Prototype to look like this: String.prototype.toXMLRPC = function(){ //<![CDATA[***your text here***]]> return "<string>" + this.replace(/</g, "<").replace(/&/g, "&")+ "</string>"; //.replace(/</g, "<").replace(/&/g, "&") } and it seems to work OK with strings now. They had the bit commented-out, so I presume that some implementations prefer the CDATA syntax. -- Jim Washington S Babu wrote:
Hello,
I've a python script that works nicely from python xmlrpclib client. I'd like to use it to work from the browser, preferably using vcXMLRPC library ( www.vcdn.org/Public/XMLRPC/).
py script is called "str" and is in http://localhost:8080/services . It takes one parameter s and has one line "return 'ret' + s
All I get in the browser is None as the return value from the service. Any idea?
--- html --
<script src="vcXMLRPC.js" type="text/javascript"></script> <script language="JavaScript" type="text/javascript"> <!-- var strService; strService = XMLRPC.getService("http://localhost:8080/"); strService.add("services.str","str") XMLRPC.onerror = function(e){ alert(e.message); return true; } var done = false; function getIt(inStr){ alert(inStr); outStr = strService.str(inStr); alert(outStr); return (outStr); } //--> </script>
TIA S Babu
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Date sent: Thu, 05 Dec 2002 11:25:21 -0500
I had the same problem last week. vcXMLRPC puts strings into a CDATA section, which seems to be a problem. I modified their String.Prototype to look like this:
My solution was to change the imports in Zope's xmlrpclib to get the better and faster sgmlop parser, which handles this correctly and is faster. In fact, I think Zope 2.6 has this "fix" now. Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax AOL-IM: BKClements
On Thu, Dec 05, 2002 at 12:21:39PM -0500, Brad Clements wrote:
In fact, I think Zope 2.6 has this "fix" now.
Yes, and some improvements in error handling as well, making it possible to use XML-RPC over cookie authentication, for example. -- Martijn Pieters | Software Engineer mailto:mj@zope.com | Zope Corporation http://www.zope.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
I've a python script that works nicely from python xmlrpclib client. I'd like to use it to work from the browser, preferably using vcXMLRPC library ( www.vcdn.org/Public/XMLRPC/).
You should have also posted your python script. I don't use the the getService method in vcXMLRPC, my javascript code is below.. Zope's xmlrpc needs an exact argument count match to call a PythonScript. So, all of my Python Scripts take two arguments: rqType="", rqDict={} where rqType is a string, and rqDict is a variable argument list. Here's some javascript code: oStruct = { orgid:currentOrgID, profiletype:profiletype, profile:selectedValue, instanceDict:handler.getInstanceDict() } updateButtonObject.disabled = true; try { result = XMLRPC.call(OrgBaseURL,OrgBaseProcessRequest,"SelectProfile",oStruct); if(result != "true") alert(result); else { loadProfilesForOrg(currentOrgID); } } catch(err) { if(err instanceof Error) alert("Unexpected Error Org UpdateProfile:"+err.message); else alert("Unexpected Error Org UpdateProfile:"+err); } oStruct ends up in rqDict in the Pythonscript, and rqType == 'SelectProfile' OrgBaseURL and stuff is set like this: var OrgBaseURL='<dtml-var "Orgs.absolute_url()">'; var OrgBaseProcessRequest = "Orgs.XMLRPCRequest_py"; Note that my javascript file is a DTML method. XMLRPCRequest_py is the PythonScript id Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax AOL-IM: BKClements
Brad, My py script is just one line return "ret" + s I had to setup vcXMLRPC to send data NOT embedded in CDATA sections as mentioned by Jim Washington. However, the final application is for tidying html source - so I need to use CDATA :-) S Babu http://vsbabu.org Brad Clements wrote:
I've a python script that works nicely from python xmlrpclib client. I'd like to use it to work from the browser, preferably using vcXMLRPC library ( www.vcdn.org/Public/XMLRPC/).
You should have also posted your python script.
I don't use the the getService method in vcXMLRPC, my javascript code is below..
Zope's xmlrpc needs an exact argument count match to call a PythonScript.
So, all of my Python Scripts take two arguments:
rqType="", rqDict={}
where rqType is a string, and rqDict is a variable argument list.
Here's some javascript code:
oStruct = { orgid:currentOrgID, profiletype:profiletype, profile:selectedValue, instanceDict:handler.getInstanceDict() } updateButtonObject.disabled = true; try { result = XMLRPC.call(OrgBaseURL,OrgBaseProcessRequest,"SelectProfile",oStruct); if(result != "true") alert(result); else { loadProfilesForOrg(currentOrgID); } } catch(err) { if(err instanceof Error) alert("Unexpected Error Org UpdateProfile:"+err.message); else alert("Unexpected Error Org UpdateProfile:"+err); }
oStruct ends up in rqDict in the Pythonscript, and rqType == 'SelectProfile'
OrgBaseURL and stuff is set like this:
var OrgBaseURL='<dtml-var "Orgs.absolute_url()">'; var OrgBaseProcessRequest = "Orgs.XMLRPCRequest_py";
Note that my javascript file is a DTML method.
XMLRPCRequest_py is the PythonScript id
Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax AOL-IM: BKClements
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Thu, Dec 05, 2002 at 12:01:44PM -0500, S Babu wrote:
I had to setup vcXMLRPC to send data NOT embedded in CDATA sections as mentioned by Jim Washington. However, the final application is for tidying html source - so I need to use CDATA :-)
I fixed Zope's XML-RPC handler for Zope 2.6.0 to deal correctly with CDATA sections (the libarary's SLowParser class didn;t handle them) *and* made sure it would use Expat for faster responses. On the whole 2.6 is far nicer to work with when you use vcXMLRPC, provided you fix up the latter as well. The authors, unfortunately, have been very unresposive to my patches. My changes were to the fault handling, preserving the fault message as well as the fault code, and fixing a bug in their fault handling that presumed a certian DOM structure. -- Martijn Pieters | Software Engineer mailto:mj@zope.com | Zope Corporation http://www.zope.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
Mmm. You said "patches" ... Any hope we could see them? Martijn Pieters wrote:
On Thu, Dec 05, 2002 at 12:01:44PM -0500, S Babu wrote:
I had to setup vcXMLRPC to send data NOT embedded in CDATA sections as mentioned by Jim Washington. However, the final application is for tidying html source - so I need to use CDATA :-)
I fixed Zope's XML-RPC handler for Zope 2.6.0 to deal correctly with CDATA sections (the libarary's SLowParser class didn;t handle them) *and* made sure it would use Expat for faster responses.
On the whole 2.6 is far nicer to work with when you use vcXMLRPC, provided you fix up the latter as well. The authors, unfortunately, have been very unresposive to my patches. My changes were to the fault handling, preserving the fault message as well as the fault code, and fixing a bug in their fault handling that presumed a certian DOM structure.
On Thu, Dec 05, 2002 at 12:42:54PM -0500, Jim Washington wrote:
Mmm. You said "patches" ... Any hope we could see them?
You beat me to it; here are all relevant changes: diff -u -r1.1 -r1.3 --- vcXMLRPC.js 2002/08/23 16:26:58 1.1 +++ vcXMLRPC.js 2002/08/26 20:23:18 1.3 @@ -590,8 +590,11 @@ //Check for XMLRPC Errors rpcErr = dom.getElementsByTagName("fault"); if(rpcErr.length > 0){ - rpcErr = this.toObject(rpcErr[0].firstChild); - this.handleError(new Error(rpcErr.faultCode, rpcErr.faultString)); + rpcErr = this.toObject(rpcErr[0].getElementsByTagName("value")[0]); + fault = new Error(rpcErr.faultCode + ': ' + rpcErr.faultString); + fault.code = rpcErr.faultCode; + fault.string = rpcErr.faultString; + this.handleError(fault) return false } The above change makes vcXMLRPC robust in the face of whitespace in the fault XML tags and preserves the XML-RPC failt string and code as attributes on the error object. -- Martijn Pieters | Software Engineer mailto:mj@zope.com | Zope Corporation http://www.zope.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
participants (4)
-
Brad Clements -
Jim Washington -
Martijn Pieters -
S Babu