gpt4 book ai didi

python - 无效的 SUDS 信封

转载 作者:太空宇宙 更新时间:2023-11-04 01:41:17 29 4
gpt4 key购买 nike

当我尝试执行这段代码时:

mmurl = 'http://server/_mmwebext/mmwebext.dll?WSDL?server=localhost'
mmclient = Client(mmurl, plugins=[EnvelopeFixer()])
loginResult = mmclient.service[1].Login(u'localhost', u'user', u'pass')

创建了以下信封:

<SOAP-ENV:Envelope xmlns:ns0="http://menandmice.com/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:Login>
<ns0:server>localhost</ns0:server>
<ns0:loginName>user</ns0:loginName>
<ns0:password>pass</ns0:password>
</ns0:Login>
</ns1:Body>
</SOAP-ENV:Envelope>

返回:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Invalid command.</faultstring>
<detail>
<mmfaultdetails>
<message>Invalid command.</message>
<errorcode>5001</errorcode>
</mmfaultdetails>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是如果我在 soapUI 中将它更改为

<SOAP-ENV:Envelope xmlns:ns0="http://menandmice.com/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns0:Login>
<ns0:server>localhost</ns0:server>
<ns0:loginName>user</ns0:loginName>
<ns0:password>pass</ns0:password>
</ns0:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

返回成功

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<LoginResponse xmlns="http://menandmice.com/webservices/">
<session>UEk6A0UC5bRJ92MqeLiU</session>
</LoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

所以我的问题是我可以强制 suds 将 body 标签创建为 <SOAP-ENV:Body>而不是 <ns1:Body>或者是

我试过这个以查看是否可以更改通过线路发送的 XML 并使用 wireshark 嗅探流量,结果证明它没有更改正在发送的消息。肯定会调用发送方法,因为我在控制台中看到了打印输出

class EnvelopeFixer(MessagePlugin):
def sending(self, context):
# context is the envelope text
print type(context)
context.envelope = context.envelope.upper()
print context.envelope

return context

我将 EnvelopeFixer 更改为使用编码而不是发送,这似乎已经成功了

class EnvelopeFixer(MessagePlugin):

def marshalled(self, context):
root = context.envelope.getRoot()
envelope = root.getChild("Envelope")
envelope.getChildren()[1].setPrefix("SOAP-ENV")
print envelope.getChildren()[1]

return context

所以现在我已经更改了 body 元素的前缀以符合服务器的要求。快乐!

最佳答案

不幸的是,RPC 端点无法正确解析 XML。一种解决方法是向您的 Client() 添加一个插件,在发送之前编辑信封。 MessagePlugin让您有机会在发送前修改 suds.sax.document.Document 或消息文本。

from suds.plugin import MessagePlugin
class EnvelopeFixer(MessagePlugin):
def sending(self, context):
# context is the envelope text
context.envelope = context.envelope.upper()
return context

client = Client(..., plugins=[EnvelopeFixer()])

关于python - 无效的 SUDS 信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4605687/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com