0

Python で (xmlrpclib を使用して) 記述された XMLRPC サーバーがあり、次のメソッドが定義されています。

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

Python クライアントを使用して接続し、ファイルを送信すると、すべて正常に動作します (ファイルが転送されます)。

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)

しかし... 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]

これから、次のエラーが発生します。

<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)

次に、Python コードからのバイナリ データと TCL コードからのバイナリ データをツール化し、それらを元のファイルと比較しました。HEX ビューで検証した後、TCL を使用して読み取ったデータには、元のデータに加えて、時々追加の HEX コードが含まれているか、一部の HEX コードがわずかに変更されていることがわかりました。

だから私はそれがバイナリデータを処理するTCLとPythonの異なる方法に関連している可能性があると推測しています。それとも、TCL で読むときに何か間違ったことをしているのですか?

PS私はまた、私に似ていると思われるこの問題を見つけましたが、解決策が正確にどうなるかわかりません.

4

1 に答える 1

1

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.

于 2014-03-14T18:29:14.480 に答える