2017-04-07 65 views
0

我正在使用一個API,需要我給出3個參數。Python - 發送參數作爲結構

string sessionKey 
int serverId 
struct date details 
     dateTime.iso8601 startDate - Optional, unless endDate is provided. 
     dateTime.iso8601 endDate - Optional. 

我不知道如何在這種情況下定義一個結構。我以這種方式調用API。

>>> server.system.provisioning.snapshot.listSnapshots(sessionKey,1000078204, {datetime.now() , datetime.now()}) 

這樣的IM定義我struct的語法:

{datetime.now() , datetime.now()} 

這給了我一個錯誤:

Traceback (most recent call last): 
    File "/usr/lib64/python3.4/xmlrpc/client.py", line 512, in __dump 
f = self.dispatch[type(value)] 
KeyError: <class 'set'> 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib64/python3.4/xmlrpc/client.py", line 1098, in __call__ 
    return self.__send(self.__name, args) 
    File "/usr/lib64/python3.4/xmlrpc/client.py", line 1431, in __request 
    allow_none=self.__allow_none).encode(self.__encoding) 
    File "/usr/lib64/python3.4/xmlrpc/client.py", line 951, in dumps 
    data = m.dumps(params) 
    File "/usr/lib64/python3.4/xmlrpc/client.py", line 504, in dumps 
    dump(v, write) 
    File "/usr/lib64/python3.4/xmlrpc/client.py", line 516, in __dump 
    raise TypeError("cannot marshal %s objects" % type(value)) 
TypeError: cannot marshal <class 'set'> objects 

難道我定義struct錯了嗎?

+0

這個問題沒有什麼關係[標籤:C] –

回答

0

在XML-RPC(您的錯誤追溯顯示您正在使用)中,「結構」是Python稱爲「dict(ionary)」的東西,但您試圖改用set。你需要使用的API文檔(即startDateendDate)中給出的鍵名來創建一個dict,即:

>>> server.system.provisioning.snapshot.listSnapshots(sessionKey,1000078204, {"startDate": datetime.now(), "endDate": datetime.now()})