Web Services Python SUDS -无法生成正确的SOAP请求

ne5o7dgx  于 2022-11-15  发布在  Python
关注(0)|答案(1)|浏览(149)

我在尝试使用SUDS生成正确的soap请求时遇到了问题。对于某个xml元素,我需要使用命名空间指定属性:

ns0:type

原规范为:

(ParameterType){
   Name =
      (NameType){
         value = None
         _required = ""
      }
   Description = None
   Value =
      (ValueType){
         Text = None
         XmlDoc = None
         _type = ""
      }
 }

所以我得到了这个xml:

<ns0:parameters>
    <ns0:Input>
       <ns0:Parameter>
          <ns0:Name required="true">Param</ns0:Name>
          <ns0:Value type="xs:Text">
             <ns0:Text>1</ns0:Text>
          </ns0:Value>
       </ns0:Parameter>
    </ns0:Input>
 </ns0:parameters>

我需要得到它这一个:

<ns0:parameters>
    <ns0:Input>
       <ns0:Parameter>
          <ns0:Name required="true">Param</ns0:Name>
          <ns0:Value ns0:type="xs:Text">
             <ns0:Text>1</ns0:Text>
          </ns0:Value>
       </ns0:Parameter>
    </ns0:Input>
 </ns0:parameters>

我尝试使用插件,但我猜它不喜欢“:“字符。下面是代码:

class MyPlugin(MessagePlugin):
    def marshalled(self, context):
        foo = context.envelope.getChild('Body').getChild('ns0:executeProcess').getChild('ns0:parameters').getChild('ns0:Input').getChild('ns0:Parameter').getChild('ns0:Value')
        foo.attributes.append(Attribute("ns0:type", "Text"))

我该如何做到这一点呢?
更多信息:suds 0.4.1 - python 2.4

sq1bmfud

sq1bmfud1#

我发现正确的插件用途:

class MyPlugin(MessagePlugin):
def marshalled(self, context):
    inputElement = context.envelope.getChild('Body').getChild('ns0:executeProcess').getChild('ns0:parameters').getChild('ns0:Input')
    parametrosElements = inputElement.getChildren()
    for i in range( len( parametrosElements ) ):
        valueElement = parametrosElements[i].getChild('ns0:Value')
        valueElement.attributes.append(Attribute("ns0:type", "Text" ))

相关问题