蟒蛇无法访问肥皂水的方法 [英] python unable to access suds methods

查看:201
本文介绍了蟒蛇无法访问肥皂水的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问使用python中SUDS的SOAP API

 从suds.client进口客户端
高清初始化():
    URL ='http://uuuuuuuuuuuuuuu.com/wewewe/WsNBI?wsdl
    用户名='XXXXX'
    密码='ppppppp
    客户端=客户端(URL)
    打印客户端
    结果= client.service.Login(nbiLogin NBILogin(用户名,密码),)
    打印结果

我无法调用登录方法,任何想法我怎么可以这样做呢?

这些都是查询返回的方法...

 肥皂水(https://fedorahosted.org/suds/)版本:0.4 GA版本:R699-20100913服务(WsNBIService)TNS =www.test.com
   prefixes(1)
      NS0 =www.test.com
   端口(1):
      (WsNBIPort)
         方法(5):
            GetClientAssociationInfo(nbiSession NBISession,clientAssociationReqData ClientAssociationReqData,)
            GetEvent(nbiSession NBISession,eventReqData EventReqData,)
            GetZDClientAssociationInfo(nbiSession NBISession,clientAssociationReqData ClientAssociationReqData,)
            登录(nbiLogin NBILogin,)
            退出(nbiSession NBISession,)
         类型(22):
            GetClientAssociationInfo
            GetClientAssociationInfoResponse
            GetEvent
            GetEventResponse
            GetZDClientAssociationInfo
            GetZDClientAssociationInfoResponse
            登录
            LoginResponse
            登出
            LogoutResponse
            authenticateResult
            clientAssociationDetail
            clientAssociationReqData
            clientAssociationResult
            eventDetail
            eventReqData
            eventResult
            EVENTTYPE
            nbiLogin
            nbiResult
            nbiSession
            请求类型

更新:

 #!的/ usr /斌/包膜蟒蛇从suds.client进口客户端高清初始化():
    URL =HTTP:// XXXXXXX / XXXX / WsNBI WSDL
    用户名='XXXXX'
    密码='PPPPPP
    客户端=客户端(URL)
    登录= client.factory.create(NS0:NBILogin)
    打印登录
    WS = login.nbiLogin(用户名=用户名,密码=密码)
    结果= client.service.Login(WS)
    打印结果
高清的main():
    初始化()如果__name__ ==__main__:
    主要()
[根@服务器脚本]#./flex_soap.py
(nbiLogin){
   用户名=无
   密码=无
 }
回溯(最近通话最后一个):
  文件./flex_soap.py19行,在?
    主要()
  文件./flex_soap.py,第16行,在主
    flexMaster()
  文件./flex_soap.py,第12行中flexMaster
    WS = login.nbiLogin(用户名=用户名,密码=密码)
AttributeError的:nbiLogin实例没有属性nbiLogin

更新:

 #!的/ usr /斌/包膜蟒蛇从suds.client进口客户端高清初始化():
    URL =的http:// XXXXX / Intune的/ WsNBI WSDL?
    用户名='UUUUU
    密码='PPPP
    客户端=客户端(URL)
    打印客户端
    登录= client.factory.create(NS0:NBILogin)
    打印登录
    login.UserName =用户名
    login.Password =密码
    结果= client.service.Login(登录)
    打印结果
    事件= client.factory.create(NS0:EventReqData)
    打印事件
高清的main():
    初始化()如果__name__ ==__main__:
    主要()[根@服务器脚本]#./flex_soap.py(nbiLogin){
   用户名=无
   密码=无
 }
(authenticateResult){
   成功=真
   会话=
      (nbiSession){
         ID =0eda1622-473c-4dd6-b68e-4ff3c1ee27f6
      }
 }
(eventReqData){
   事件类型=
      (EVENTTYPE){
         值=无
      }
   SerialNumbers =
      (SerialNumbers){
         的SerialNumber [] =<&空GT;
      }
 }

任何想法如何,我可以得到这个方法

  GetEvent(nbiSession NBISession,eventReqData EventReqData,)


解决方案

您code是不是一个有效的Python。 登录(nbiLogin NBILogin,)意味着有登录接受类型的单个参数的方法 NBILogin 。这不是一个文字语法,你应该使用。尝试是这样的:

 登录= client.factory.create(NS0:NBILogin)
 login.UserName =用户名
 login.Password =密码
 结果= client.service.Login(登录)

此输出:

 (authenticateResult){
   成功=真
   会话=
      (nbiSession){
         ID =0eda1622-473c-4dd6-b68e-4ff3c1ee27f6
      }
 }

意味着 result.Success ==真与result.Session.Id ==0eda1622-473c-4dd6-b68e-4ff3c1ee27f6

GetEvent(nbiSession NBISession,eventReqData EventReqData,)意味着你需要的类型2参数 NBISession EventReqData

您可以从结果获取会话。要建立 EventReqData

 (eventReqData){
   事件类型=
      (EVENTTYPE){
         值=无
      }
   SerialNumbers =
      (SerialNumbers){
         的SerialNumber [] =<&空GT;
      }
 }

您需要创建事件类型 SerialNumbers

  event_req_data = client.factory.create(NS0:EventReqData)
event_req_data.EventType =这里放一些适当的事件类型
event_req_data.SerialNumbers = [10,51,1]#有些序列号

以上假设序列号是整数,否则创建的每个的SerialNumber 相同的方式,通过 client.factory.create所有其他对象()

  SNS = event_req_data.SerialNumbers = client.factory.create('NS0:SerialNumbers')
在项[10 51,1]:
    NS = client.factory.create('NS0:的SerialNumber)
    ns.value =项目
    sns.SerialNumber.append(NS)

我不明白 SerialNumbers 的SerialNumber 类型的房源,所以可能会失败。

如果泡沫不从字符串转换为事件类型本身则可以创建事件类型使用 client.factory.create()明确:

  EVENT_TYPE = client.factory.create(NS0:事件类型)
event_type.value =把一些合适的事件在这里输入
event_req_data.EventType = EVENT_TYPE

请来电:

 事件= client.service.GetEvent(login.Session,event_req_data)

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

解决方案

Your code is not a valid Python. Login(nbiLogin NBILogin, ) means that there is a method Login that accepts a single argument of type NBILogin. It is not a literal syntax that you should use. Try something like this:

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

This output:

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

means that result.Success == True and result.Session.Id == "0eda1622-473c-4dd6-b68e-4ff3c1ee27f6".

GetEvent(nbiSession NBISession, eventReqData EventReqData, ) means that you need 2 arguments of types NBISession and EventReqData.

The session you could get from result. To build EventReqData:

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

you need to create EventType and 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 

The above assumes that serial numbers are integers otherwise create each SerialNumber the same way as all other objects via 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)

I don't see SerialNumbers, SerialNumber types in the listing so it might fail.

If suds doesn't convert from string to EventType by itself then you could create EventType using client.factory.create() explicitly:

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

Make the call:

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

这篇关于蟒蛇无法访问肥皂水的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆