我在与Axis2上运行的SOAP API正确交互时遇到了一个问题:
发生的情况是,我应该使用两个参数(loginName和password)调用登录方法,它将返回一个身份验证令牌,我将在随后的交互中使用该令牌。
#!/usr/bin/python
from SOAPpy import SOAPProxy
s_user = 'Administrator'
s_pass = 'securityThroughObscurity'
s_host = '192.168.76.130:8998'
namespace = 'http://bcc.inc.com/IncSecurity'
url = 'http://' + s_host + '/axis2/services/IncSecurityService'
DHCPServ = SOAPProxy(url, namespace)
DHCPServ.config.dumpSOAPOut = 1
DHCPServ.config.dumpSOAPIn = 1
DHCPResp = DHCPServ.login(loginName=s_user, password=s_pass)另一端的Axis2服务器返回一个声明为Data element of the OM Node is NULL的XML错误。查看Axis2日志,我发现错误是adb_login.c(383) non nillable or minOuccrs != 0 element loginName missing
然后,我从一个已知工作的login客户端与来自该客户端的XML进行数据包捕获,这是两者之间的区别:
SOAPpy:
<ns1:login xmlns:ns1="http://bcc.inc.com/IncSecurity" SOAP-ENC:root="1">
<password xsi:type="xsd:string">securityThroughObscurity</password>
<loginName xsi:type="xsd:string">Administrator</loginName>
</ns1:login>Java:
<ns2:login xmlns:ns2="http://bcc.inc.com/IncSecurity">
<ns2:loginName>Administrator</ns2:loginName>
<ns2:password>securityThroughObscurity</ns2:password>
</ns2:login>因此,这意味着由于某种原因(可能与我缺乏Python和SOAPpy知识有关),名称空间没有应用于login方法中使用的变量,因此所有人都认为它们实际上并不存在,因此错误是合理的。
此外,它似乎颠倒了变量,将密码放在loginName之前,但我认为这并不重要。
我做错了什么?
发布于 2011-04-26 18:22:35
看起来这是SOAPPy中的一个已知错误,有人建议使用一个简单的补丁:http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523083
或者(假设您可以访问服务WSDL),SOAPPy允许您指定WSDL,而不仅仅是名称空间。这看起来将为信封生成代码提供更好的名称空间信息。http://diveintopython.net/soap_web_services/introspection.html
最后,如果SOAPPy不适合您,可以尝试Suds (它是better documented而不是SOAPPy)。
from suds.client import Client
from suds.wsse import *
client = Client(WSDL_LOCATION)
guid = client.service.someFunctionName("a string argument", 42)祝好运!
https://stackoverflow.com/questions/5493349
复制相似问题