我在正确连接 Axis2 上运行的 SOAP API 时遇到问题:
我应该用两个参数(loginName 和 password)调用登录方法,它会返回一个我将用于后续交互的身份验证 token 。
#!/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 服务器返回一个 XML 错误,说明 OM 节点的数据元素为 NULL
。查看 Axis2 日志,我发现错误是 adb_login.c(383) non nillable or minOuccrs != 0 element loginName missing
然后我从已知工作的 Java 客户端和来自该客户端的 XML 数据包捕获 login
XML,这些是两者之间的区别:
SOAP :
<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 之前,但我认为这无关紧要。
我做错了什么?
最佳答案
看起来这是 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)
祝你好运!
关于python - SOAPpy 中的 namespace 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5493349/