2012-07-28 142 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