0

I am trying to access the SOAP api using SUDS in 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

i am unable to invoke the Login method, any idea how i can do this?

these are the methods returned by the query...

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


[root@server 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()

[root@server 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>
      }
 }

any idea how i can get this method

GetEvent(nbiSession NBISession, eventReqData EventReqData, )
4

1 に答える 1

1

あなたのコードは有効な Python ではありません。type の単一の引数を受け入れるLogin(nbiLogin NBILogin, )メソッドがあることを意味します。これは、使用すべきリテラル構文ではありません。次のようなことを試してください:LoginNBILogin

 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, )NBISessionは、タイプとの 2 つの引数が必要であることを意味しますEventReqData

から取得できるセッションresult。ビルドするにはEventReqData:

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

作成する必要がありEventTypeますSerialNumbers

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 

上記は、シリアル番号が整数であると仮定しています。それ以外の場合は、次の方法SerialNumberで他のすべてのオブジェクトと同じ方法で作成しclient.factory.create()ます

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リストに,SerialNumberタイプが表示されないため、失敗する可能性があります。

suds が文字列からそれ自体に変換されない場合は、明示的に使用して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)
于 2012-07-28T19:51:44.603 に答える