title: Python - Suds. How to edit the namespaces of SOAP-ENV:Envelope
body: <p>I am creating a request to consume a Web Service using SUDS (4.0) in Django.
  However Suds is not putting the right namespaces.</p>
  <p>The Soap Envelope I am getting:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;SOAP-ENV:Envelope 
      xmlns:ns3=&quot;http://www.w3.org/2001/XMLSchema&quot; 
      xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; 
      xmlns:ns0=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; 
      xmlns:ns1=&quot;http://factura360.com/invoice_webservice&quot; 
      xmlns:ns2=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; 
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
      xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; 
      SOAP-ENV:encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;&gt;
      &lt;SOAP-ENV:Header&gt;
          &lt;ns2:LoginObject&gt;
              &lt;soapusername&gt;USER&lt;/soapusername&gt;
              &lt;soappassword&gt;PASSWORD&lt;/soappassword&gt;
          &lt;/ns2:LoginObject&gt;
      &lt;/SOAP-ENV:Header&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns1:generate_invoice&gt;
              &lt;document xsi:type=&quot;xsd:string&quot;&gt;
                  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;cfdi:Comprobante&gt;&lt;/cfdi:Comprobante&gt;
              &lt;/document&gt;
              &lt;documenttype xsi:type=&quot;xsd:int&quot;&gt;0&lt;/documenttype&gt;
              &lt;filetype xsi:type=&quot;xsd:int&quot;&gt;1&lt;/filetype&gt;
              &lt;cer xsi:nil=&quot;true&quot;&gt;&lt;/cer&gt;&lt;key xsi:nil=&quot;true&quot;&gt;
              &lt;/key&gt;&lt;password xsi:type=&quot;xsd:string&quot;&gt;PASSWORD&lt;/password&gt;
          &lt;/ns1:generate_invoice&gt;
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  <p>What the SOAP Envelope should be:</p>
  <pre><code>&lt;SOAP-ENV:Envelope 
      xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; 
      xmlns:ns1=&quot;http://factura360.com/invoice_webservice&quot; 
      xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; 
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xmlns:ns2=&quot;namespace&quot; 
      xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;
      SOAP-ENV:encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;&gt; 
      &lt;SOAP-ENV:Header&gt;
             &lt;ns2:LoginObject&gt; 
                 &lt;soapusername&gt;USER&lt;/soapusername&gt; 
                 &lt;soappassword&gt;PASSWORD&lt;/soappassword&gt; 
             &lt;/ns2:LoginObject&gt;
      &lt;/SOAP-ENV:Header&gt; 
      &lt;SOAP-ENV:Body&gt;
          &lt;ns1:generate_invoice&gt; 
              &lt;document xsi:type=&quot;xsd:string&quot;&gt; 
                  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;cfdi:Comprobante&gt;    &lt;/cfdi:Comprobante&gt;
             &lt;/document&gt;
             &lt;documenttype xsi:type=&quot;xsd:int&quot;&gt;0&lt;/documenttype&gt; 
             &lt;filetype xsi:type=&quot;xsd:int&quot;&gt;1&lt;/filetype&gt;
             &lt;cer xsi:nil=&quot;true&quot;&gt;&lt;/cer&gt; 
             &lt;key xsi:nil=&quot;true&quot;&gt;&lt;/key&gt;
             &lt;password xsi:type=&quot;xsd:string&quot;&gt;PASSWORD&lt;/password&gt; 
          &lt;/ns1:generate_invoice&gt; 
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  <p>So, according to the desired SOAP Envelope, there should be no 'xmlns:ns0', no 'xmlns:ns3', there should be xmlns:xsd with value 'http://www.w3.org/2001/XMLSchema' and 'xmlns:ns2' should have  a value of 'namespace'.</p>
  <p>My actual function to edit the Envelope is this one:</p>
  <pre><code>class CorrectNamespace(MessagePlugin):
      def marshalled(self, context):
          soap_env_parent = context.envelope
          soap_env_parent.set('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema')
          soap_env_parent.unset('xmlns:ns0')
          soap_env_parent.unset('xmlns:ns3')
          soap_env_parent.unset('xmlns:ns2')
          soap_env_parent.set('xmlns:ns2', 'namespace')
  
  factura_client = Client(settings.FACTURA360_URL, plugins=[CorrectNamespace()])
  
  #Setting the Login Object
  lg_element = Element('ns2:LoginObject')
  soapuser_element = Element('soapusername').setText(settings.FACTURA360_USER)
  soappass_element = Element('soappassword').setText(settings.FACTURA360_PASS)
  lg_element.append(soapuser_element)
  lg_element.append(soappass_element)
  factura_client.set_options(soapheaders=lg_element)
  
  #The call to the webservice
  invoice = factura_client.service.\
      generate_invoice(document, document_type, filetype,
                       cer, key, settings.FACTURA360_INVOICEPASSWORD)
  </code></pre>
  <p>Unfortunately, my plugin function is adding 'xmlns:xsd' and 'xmlns:ns2', but it is not deleting the others.</p>
  <p>Here is the resulting Envelope with the plugin function:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;SOAP-ENV:Envelope 
      xmlns:ns3=&quot;http://www.w3.org/2001/XMLSchema&quot; 
      xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; 
      xmlns:ns0=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; 
      xmlns:ns1=&quot;http://factura360.com/invoice_webservice&quot; 
      xmlns:ns2=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; 
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
      xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; 
      SOAP-ENV:encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; 
      xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; 
      xmlns:ns2=&quot;namespace&quot;&gt;
  </code></pre>
  <p>How do I delete the other namespaces?</p>