[Django]-Consume WSDL url with XML with escaped chars as argument

2👍

I think the suds library is the culprit here. When you send your escaped xml into suds as a parameter to the client.service.timbrado method it also escapes it. However, it sees that you have escaped the ampersand already like this:

...
descripcion="EJE&MPLO"
...

And it does not escape it further (although it should). You should run your escaped xml through xml.sax.saxutils.escape before passing it to client.service.timbrado.

This should result in xml snippet above looking like this:

...
descripcion="EJE&MPLO"
...

When I run your code with the doubly-escaped xml, I receive the following result:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:timbradoResponse xmlns:ns2="http://sefactura.com">
            <return>
                <status>401 - Fecha y hora de generación fuera de rango</status>
            </return>
        </ns2:timbradoResponse>
    </S:Body>
</S:Envelope>

It is an error regarding your data (date and time of generation out of range), not about the format of the xml.

2👍

You are easily able to ‘escape’ any XML values before it goes over to the service. Check out http://wiki.python.org/moin/EscapingXml

>>> from xml.sax.saxutils import escape
>>>
>>> escape("< & >")
'&lt; &amp; &gt;'

This has worked for me in the past to do exactly what you’re describing, pass XML data over a the net to a page.

According to http://www.xmlnews.org/docs/xml-basics.html#references , just escaping the data before its sent will work just fine.

To work off of your example XML

...
descripcion="EJE&MPLO"
...

after it goes through will be

...
descripcion="EJE&amp;MPLO"
...

1👍

Have you tried escaping them twice?

If the service is broken, you should file a bug-report and take precautions so you will notice it when it gets fixed and your workaround should be removed.

Leave a comment