2012-07-28 119 views
0

我試圖訪問使用肥皂水在Python蟒蛇無法訪問泡沫方法

from suds.client import Client 
def initialize(): 
    url = 'http://uuuuuuuuuuuuuuu.com/wewewe/WsNBI?wsdl' 
    username = 'xxxxx' 
    password = 'ppppppp' 
    client = Client(url) 
    print client 
    result = client.service.Login(nbiLogin NBILogin(username,password),) 
    print result 

我無法調用登錄方法,任何想法我怎麼能做到這一點的SOAP API?

這些都是通過查詢返回的方法...

Suds (https://fedorahosted.org/suds/) version: 0.4 GA build: R699-20100913 

Service (WsNBIService) tns="www.test.com" 
    Prefixes (1) 
     ns0 = "www.test.com" 
    Ports (1): 
     (WsNBIPort) 
     Methods (5): 
      GetClientAssociationInfo(nbiSession NBISession, clientAssociationReqData ClientAssociationReqData,) 
      GetEvent(nbiSession NBISession, eventReqData EventReqData,) 
      GetZDClientAssociationInfo(nbiSession NBISession, clientAssociationReqData ClientAssociationReqData,) 
      Login(nbiLogin NBILogin,) 
      Logout(nbiSession NBISession,) 
     Types (22): 
      GetClientAssociationInfo 
      GetClientAssociationInfoResponse 
      GetEvent 
      GetEventResponse 
      GetZDClientAssociationInfo 
      GetZDClientAssociationInfoResponse 
      Login 
      LoginResponse 
      Logout 
      LogoutResponse 
      authenticateResult 
      clientAssociationDetail 
      clientAssociationReqData 
      clientAssociationResult 
      eventDetail 
      eventReqData 
      eventResult 
      eventType 
      nbiLogin 
      nbiResult 
      nbiSession 
      requestType 

UPDATE:

#!/usr/bin/env python 

from suds.client import Client 

def initialize(): 
    url = 'http://xxxxxxx/xxxx/WsNBI?wsdl' 
    username = 'xxxxx' 
    password = 'pppppp' 
    client = Client(url) 
    login = client.factory.create("ns0:NBILogin") 
    print login 
    ws = login.nbiLogin(userName=username, password = password) 
    result = client.service.Login(ws) 
    print result 
def main(): 
    initialize() 

if __name__ == "__main__": 
    main() 


[[email protected] scripts]# ./flex_soap.py 
(nbiLogin){ 
    UserName = None 
    Password = None 
} 
Traceback (most recent call last): 
    File "./flex_soap.py", line 19, in ? 
    main() 
    File "./flex_soap.py", line 16, in main 
    flexMaster() 
    File "./flex_soap.py", line 12, in flexMaster 
    ws = login.nbiLogin(userName=username, password = password) 
AttributeError: nbiLogin instance has no attribute 'nbiLogin' 

UPDATE:

#!/usr/bin/env python 

from suds.client import Client 

def initialize(): 
    url = 'http://xxxxx/intune/WsNBI?wsdl' 
    username = 'uuuuu' 
    password = 'pppp' 
    client = Client(url) 
    print client 
    login = client.factory.create("ns0:NBILogin") 
    print login 
    login.UserName = username 
    login.Password = password 
    result = client.service.Login(login) 
    print result 
    event = client.factory.create("ns0:EventReqData") 
    print event 
def main(): 
    initialize() 

if __name__ == "__main__": 
    main() 

[[email protected] scripts]# ./flex_soap.py 

(nbiLogin){ 
    UserName = None 
    Password = None 
} 
(authenticateResult){ 
    Success = True 
    Session = 
     (nbiSession){ 
     Id = "0eda1622-473c-4dd6-b68e-4ff3c1ee27f6" 
     } 
} 
(eventReqData){ 
    EventType = 
     (eventType){ 
     value = None 
     } 
    SerialNumbers = 
     (SerialNumbers){ 
     SerialNumber[] = <empty> 
     } 
} 

任何想法如何,我可以得到這種方法

GetEvent(nbiSession NBISession, eventReqData EventReqData,) 

回答

1

您的代碼不是有效的Python。 Login(nbiLogin NBILogin,)表示有一種方法Login,它接受NBILogin類型的單個參數。這不是您應該使用的文字語法。嘗試是這樣的:

login = client.factory.create("ns0:NBILogin") 
login.UserName = username 
login.Password = password 
result = client.service.Login(login) 

此輸出:

(authenticateResult){ 
    Success = True 
    Session = 
     (nbiSession){ 
     Id = "0eda1622-473c-4dd6-b68e-4ff3c1ee27f6" 
     } 
} 

意味着result.Success == True and result.Session.Id == "0eda1622-473c-4dd6-b68e-4ff3c1ee27f6"

GetEvent(nbiSession NBISession, eventReqData EventReqData,)表示需要2個參數NBISessionEventReqData

您可以從result獲得的會話。要建立EventReqData

(eventReqData){ 
    EventType = 
     (eventType){ 
     value = None 
     } 
    SerialNumbers = 
     (SerialNumbers){ 
     SerialNumber[] = <empty> 
     } 
} 

您需要創建EventTypeSerialNumbers

event_req_data = client.factory.create("ns0:EventReqData") 
event_req_data.EventType = "put some appropriate event type here" 
event_req_data.SerialNumbers = [10, 51, 1] # some serial numbers 

上述假定的序列號是整數通過client.factory.create()否則創建的每個SerialNumber相同的方式,所有其他對象:

sns = event_req_data.SerialNumbers = client.factory.create('ns0:SerialNumbers') 
for item in [10, 51, 1]: 
    ns = client.factory.create('ns0:SerialNumber') 
    ns.value = item 
    sns.SerialNumber.append(ns) 

我看不到SerialNumbers,列表中的個類型,因此可能會失敗。

如果泡沫本身不從字符串轉換爲EventType,那麼你可以使用EventTypeclient.factory.create()明確創建:

event_type = client.factory.create("ns0:EventType") 
event_type.value = "put some appropriate event type here" 
event_req_data.EventType = event_type 

請來電:

event = client.service.GetEvent(login.Session, event_req_data) 
+0

感謝塞巴斯蒂安,我得到了一些輸出,它現在說「nbiLogin實例沒有屬性'nbiLogin'」,對不起,我是肥皂API的新手......我還打印了nbiLogin可以如何填充......任何想法? – krisdigitx 2012-07-28 20:13:38

+0

@krisdigitx:我已經更新了考慮到來自'print login'的信息的答案。 – jfs 2012-07-28 20:19:23

+0

謝謝sebastian工作,現在我想訪問其他方法r「GetEvent(nbiSession NBISession,eventReqData EventReqData,)」任何想法?感謝這真的很感謝...我已附加更新的輸出... – krisdigitx 2012-07-28 20:37:13