Question

I have an XMLRPC server written in Python (using xmlrpclib) that has the following method defined:

def saveFileOnServer(fileName, xmldata):
    handle = open(fileName, "wb")
    handle.write(xmldata.data)
    handle.close()
    return 0

If I'm using a Python client to connect and send the file, everything works ok (file is transferred):

import sys, xmlrpclib
client = xmlrpclib.Server('http://10.205.11.28:10044')
with open("resource.res", "rb") as handle:
    binary_data = xmlrpclib.Binary(handle.read())
client.saveFileOnServer("C:\\Location\\resource.res",binary_data)

But... I have to connect to this XMLRPC server from a TCL script. And I'm doing the following:

package require XMLRPC
package require SOAP
package require rpcvar
package require http
set fd [open "resource.res" r]
fconfigure $fd -translation binary
set data [read $fd]
close $fd

XMLRPC::create ::PytharAgent::saveFileOnServer -name "saveFileOnServer" -proxy [::PytharAgent::endpoint] -params {fileName string file binary}
puts [::PytharAgent::saveFileOnServer "C:\\Location\\resource.res" $data]

From this I get the following error:

<class 'xml.parsers.expat.ExpatError'>:not well-formed (invalid token): line 2, column 154
    invoked from within
"$parseProc $procVarName $reply"
    (procedure "invoke2" line 17)
    invoked from within
"invoke2 $procVarName $reply"
    (procedure "::SOAP::invoke" line 25)
    invoked from within
"::SOAP::invoke ::SOAP::_PytharAgent_saveFileOnServer {C:\Location\resource.res} IxNResourceItev1.0.0.0JTYPE2\tm_versio..."
    ("eval" body line 1)
    invoked from within
"eval ::SOAP::invoke ::SOAP::_PytharAgent_saveFileOnServer $args"
    (procedure "::PytharAgent::saveFileOnServer" line 1)
    invoked from within
"::PytharAgent::saveFileOnServer "C:\\Location\\resource.res" $data"
    invoked from within
"puts [::PytharAgent::saveFileOnServer "C:\\Location\\resource.res" $data]"
    (file "test.pythat-agent.tcl" line 109)

I then tool the binary data from the Python code and the binary data from the TCL code and compared them with the original file. I discovered after verifying in HEX view that the data read using TCL had the original data plus some extra HEX codes from time to time or with some HEX codes slightly modified.

So i'm guessing it might be related to the TCL vs. Python different ways of handling binary data. Or am I doing something wrong when reading with TCL?

PS I also found this issue that seems to be similar to mine, but I don't understand what the solution would be exactly.

Was it helpful?

Solution

Try this:

package require base64
XMLRPC::create ::PytharAgent::saveFileOnServer -name "saveFileOnServer" -proxy [::PytharAgent::endpoint] -params {fileName string file base64}
puts [::PytharAgent::saveFileOnServer "C:\\Location\\resource.res" [::base64::encode $data]]]

basically binary seems not to be a recognized datatype of XMLRPC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top