Python SUDS - не удается сгенерировать правильный SOAP-запрос - PullRequest
2 голосов
/ 16 января 2012

У меня проблема с попыткой сгенерировать правильный запрос мыла с помощью SUDS.Для определенного элемента 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

1 Ответ

3 голосов
/ 01 марта 2012

Я нашел правильное использование плагина:

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