Note that there are some explanatory texts on larger screens.

plurals
  1. POEncoding Issue while Parsing XML
    text
    copied!<p>I'm trying to parse an xml with minidom (python). I have an url with my xml data.</p> <p>But I get an error :</p> <p><strong>DjangoUnicodeDecodeError</strong></p> <p>Seems it's an encoding issue when parsing!</p> <p>This is my code:</p> <pre><code>url = "http://sirh6.eolia-software.com/wscvsearch.asp" datasource = urllib2.urlopen(url) data = datasource.read()#read() to get the sourcecode of the url dom = parseString(data) handleElements(dom) </code></pre> <p>My xml: </p> <pre><code> &lt;!--?xml version="1.0" encoding="ISO-8859-1" ?--&gt; ... (see the source code of the url above) </code></pre> <p>I tried :</p> <p>1- </p> <pre><code>url = "http://sirh6.eolia-software.com/wscvsearch.asp" datasource = urllib2.urlopen(url) data = datasource.read().decode('iso8859-1') dom = parseString(data) </code></pre> <p>I get :</p> <pre><code> UnicodeEncodeError 'ascii' codec can't encode character u'\x92' in position 345: ordinal not in range(128) The string that could not be encoded/decoded was: nce darchi </code></pre> <p>Traceback:</p> <pre><code>File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/annoying/decorators.py" in wrapper 74. output = function(request, *args, **kwargs) File "/home/astrocybernaute/projects/emploi/views.py" in parse_xml 880. dom = parseString(data) File "/usr/lib/python2.7/xml/dom/minidom.py" in parseString 1924. return expatbuilder.parseString(string) File "/usr/lib/python2.7/xml/dom/expatbuilder.py" in parseString 940. return builder.parseString(string) File "/usr/lib/python2.7/xml/dom/expatbuilder.py" in parseString 223. parser.Parse(string, True) Exception Type: UnicodeEncodeError at /emploi/xml/ Exception Value: 'ascii' codec can't encode character u'\x92' in position 345: ordinal not in range(128) </code></pre> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload