suds WebFault最可能是不正确的SOAPAction

时间:2014-04-03 21:12:16

标签: python soap wsdl suds

我已经检查过发布的与此类似的其他问题,我所看到的都是同样的问题。我将发布这个问题的suds和pysimplesoap。我不关心我上班的哪一个,但我有点需要让其中一个人尽快工作。我认为问题可能在于WSDL是由.NET中创建的服务生成的,因为我遇到了与pysimplesoap和我尝试过的所有其他python soap客户端相同的问题。我用suds和suds-jurko尝试了同样的结果。我对这个SOAP的东西并不擅长(我宁愿使用简单的RESTful服务和JSON)所以任何帮助都会非常感激。我会对我的问题进行投票并标记已接受的解决方案。

Here is the WSDL file

这是我的代码:

from suds.client import Client
client = Client('http://url-for-my-service?wsdl')
result = client.service.StartSession('userid','passwd')

以下是我收到的错误消息:

ERROR:suds.client:<suds.sax.document.Document instance at 0x28fcbd8>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 581, in invoke
    result = self.send(soapenv)
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault

我有点像suds更好,因为我可以启用logging.DEBUG并获取更多信息:

DEBUG:suds.client:sending to (http://cpldevweb001:3691/Invoke?Handler=CSSoapService)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:CSSoapService" xmlns:ns2="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:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Header/>
   <ns2:Body>
      <ns1:StartSession>
         <user xsi:type="ns3:string">userid</user>
         <pass xsi:type="ns3:string">passwd</pass>
      </ns1:StartSession>
   </ns2:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': '"#StartSession"', 'Content-Type': 'text/xml; charset=utf-8'}
DEBUG:suds.client:HTTP failed - 500 - Internal Server Error:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
   <SOAP:Fault>
     <faultcode>SOAP:Client</faultcode>
     <faultcode>Invalid Request</faultcode>
     <detail>Invalid SOAP Request, most probable incorrect SOAPAction</detail>
   </SOAP:Fault>
  </SOAP:Body>
</SOAP:Envelope>

1 个答案:

答案 0 :(得分:0)

供应商提供了一个工作样本客户端,我可以使用TcpMon运行它,并将发送的XML与suds生成的内容进行比较。事实证明问题是空的<SOAP-ENV:Header/>标记。

我创建了一个消息插件,用于在发送阶段过滤掉空标题,现在它可以正常工作。这是更新的代码:

import re

from suds.client import Client
from suds.plugin import MessagePlugin

class HeaderFilter(MessagePlugin):

    def sending(self, context):
        context.envelope = re.sub(r'<[A-Za-z0-9_\-:]*Header/>', '', context.envelope)
        return context

client = Client('http://url-for-my-service?wsdl', plugins=[HeaderFilter()]) 
result = client.service.StartSession('userid','passwd')

我可能更具体而不是使用正则表达式,但我不知道它是否总是使用SOAP-ENV前缀。