无效的泡沫信封

2024-10-01 17:29:55 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图执行此代码时:

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

将创建以下信封:

^{pr2}$

返回:

<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嗅探通信量,结果发现它没有更改正在发送的消息。因为我在控制台中看到了打印输出,所以肯定会调用sending方法

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以使用marshaled而不是sending,这似乎已经做到了这一点

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元素的前缀,以符合服务器的要求。快乐!在


Tags: orgenvhttpserverwwwcontextbodysoap
1条回答
网友
1楼 · 发布于 2024-10-01 17:29:55

不幸的是,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()])

相关问题 更多 >

    热门问题