2015-05-14 23 views
2

我已經設置了一個小的測試java應用程序,它在啓動pyro服務器(在python中)後調用python腳本。除了現在我想把一個對象作爲參數傳遞給它的方法,它工作得很好。我從Python端說法例外:如何使用pyro以對象作爲參數調用python

Pyro4.errors.SerializeError: unsupported serialized class: 
com.test.pyro4.TestLog 

根據火焰兵文檔類將得到轉換爲在python的字典,但我甚至不能走到這一步。

java代碼:

NameServerProxy ns = NameServerProxy.locateNS("localhost"); 
PyroProxy remotePluginObject = new PyroProxy(ns.lookup("plugin")); 

int length = 5; 
double[] values = new double[] { 0.5, 0.3, 0.6, 05, 0.4 }; 
double a = 6.94; 
double b = 2.17; 

remoteObject = new PyroProxy(ns.lookup("test.object")); 
remoteObject.call("setValues", values, length); 

Object result = remoteObject.call("calculate", remoteObject, a, b); 

System.out.println(result.toString()); 

remotePluginObject.close();    
remoteObject.close(); 
ns.close(); 

蟒蛇服務器代碼:

class TestObject(object): 
values=[] 
length=0 

def setValues(self, valuesArray, lengthValue): 
    values=valuesArray 
    length=lengthValue  

class Plugin(object): 
def calculate(self, obj, a, b): 
    result = example.calculate(obj, a, b) 
    return result 

plugin=Plugin() 
obj=TestObject() 

daemon=Pyro4.Daemon() 
ns=Pyro4.locateNS() 

pluginURI=daemon.register(plugin) 
ns.register("plugin", pluginURI) 

objURI=daemon.register(obj) 
ns.register("test.object", objURI) 

daemon.requestLoop() 
+0

代碼已被更新,以顯示它現在是如何工作的。對象是在python端創建的,然後通過java端的代理請求,設置值,然後用於調用python方法。 – user1584120

+0

我說得太快了。以上代碼不起作用。獲取以下錯誤:TypeError:'float'對象不可迭代。我已經把所有的參數從調用中剝離出來,只留下對象,它似乎是什麼? – user1584120

回答

0

嘗試串行器設置爲pickle

Pyro4.config.SERIALIZER = 'pickle' 

要知道,這已經security implications

而這在Java中:

Config.SERIALIZER = Config.SerializerType.pickle; 
+0

同樣的錯誤,是否有一個這需要的certian的地方?我在uri的打印之前添加了它 – user1584120

+0

把它放在第一行並重新開始一切。 –

+0

我現在得到的錯誤太長,無法粘貼,但在一行中說:Pyro4.errors.SerializeError:使用的消息序列化程序未被接受:4.啓動服務器時發生這種情況,而不是嘗試調用方法時從java – user1584120

相關問題