我有一个用Python编写的XMLRPC服务器(使用xmlrpclib),它定义了以下方法:def saveFileOnServer(fileName, xmldata):
handle = open(fileName, "wb")
handle.write(xmldata.data)
handle.close()
return 0
如果我使用Python客户机连接并发送文件,则一切正常(文件已传输):
^{pr2}$
但是。。。我必须从TCL脚本连接到这个XMLRPC服务器。我要做的是: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]
由此得出以下错误::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)
然后,我将Python代码中的二进制数据和TCL代码中的二进制数据与原始文件进行比较。我在HEX视图中验证后发现,使用TCL读取的数据有原始数据加上一些时不时额外的十六进制代码,或是稍微修改了一些十六进制代码。在
所以我猜这可能与TCL和Python处理二进制数据的不同方式有关。还是我在读TCL的时候做错了什么?在
PS我还发现了this issue似乎和我的很相似,但我不知道确切的解决方案是什么。在