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

标签 python web-services plugins soap suds

我在尝试使用 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

最佳答案

我找到了正确的插件用法:

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

关于Python SUDS - 无法生成正确的 SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8878645/

相关文章:

plugins - 安装 vagrant-vsphere 插件

plugins - Pentaho Data Integration (PDI) 9.4 Marketplace 缺失,现在如何安装插件?

python - 访问 GREL/Open Refine(或 R、Python)中特定值的列名称

python - 如何根据我自己的训练数据微调来自 OpenAI 的 Whisper ASR 的模型?

jQuery - 实时验证插件

java - WSDL网络服务

c# - 如何将 WS-Addressing 字段添加到 SOAP 消息

python - 如何将 QTimeEdit 中的小时、分钟值显示到相应的 LCD 上?

python - 从哪里获得 Python ANTLR 包以使用 StringTemplate?

java - 我们可以对 REST 服务进行 UDP 调用吗