SOAPpy 中的命名空间未按预期工作

发布于 2024-10-29 12:20:16 字数 1484 浏览 4 评论 0原文

我在与 Axis2 上运行的 SOAP API 正确连接时遇到问题:

我应该使用两个参数(loginName 和密码)调用登录方法,并且它返回一个身份验证令牌,我将使用该令牌进行后续交互。

#!/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,以下是两者之间的差异:

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 方法中使用的变量,因此对于所有帐户来说,它们实际上并不存在,并且错误是有道理的。

另外,它似乎正在翻转变量并将密码放在登录名之前,但我认为这并不重要。

我做错了什么?

I'm having an issue correctly interfacing with a SOAP API running on Axis2:

What happens is I should call the login method with two arguments (loginName and password) and it returns an authentication token that I will use for subsequent interaction.

#!/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)

The Axis2 server on the other side returns an XML error stating Data element of the OM Node is NULL. Looking at the Axis2 logs, I see the error is adb_login.c(383) non nillable or minOuccrs != 0 element loginName missing

I then packet captured the login XML from a known working Java client versus the XML from this client and these are the differences between the two:

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>

So this means that for some reason (probably related to my lack of knowledge in Python and SOAPpy) the namespace is not being applied to the variables being used in the login method, so by all accounts they don't actually exist and the error is warranted.

Also, it seems to be flipping the variables around and putting the password before loginName but I don't think that matters much.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪我终i 2024-11-05 12:20:16

看起来这是 SOAPy 中的一个已知错误,有人建议了一个简单的补丁: http ://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523083

或者(假设您有权访问服务 WSDL),SOAPy允许您指定 WSDL 而不仅仅是名称空间。这看起来将为信封生成代码提供更好的命名空间信息。 http://diveintopython.net/soap_web_services/introspection.html

最后,如果 SOAPy 不是为您工作,请尝试 Suds (它是比 SOAPy 有更好的记录)。

from suds.client import Client
from suds.wsse import *
client = Client(WSDL_LOCATION)
guid = client.service.someFunctionName("a string argument", 42)

祝你好运!

Looks like it's a known bug in SOAPPy, someone has suggested a simple patch: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523083

Alternately (assuming you have access to the service WSDL), SOAPPy lets you specify a WSDL instead of just a namespace. This looks like it will provide better namespace information to the envelope generation code. http://diveintopython.net/soap_web_services/introspection.html

Finally, if SOAPPy just isn't working for you, try Suds (it's better documented than SOAPPy).

from suds.client import Client
from suds.wsse import *
client = Client(WSDL_LOCATION)
guid = client.service.someFunctionName("a string argument", 42)

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文