Note that there are some explanatory texts on larger screens.

plurals
  1. POXML Encoding error while writing it in to file
    text
    copied!<p>I think I am following the right approach but I am still getting an encoding error:</p> <pre><code>from xml.dom.minidom import Document import codecs doc = Document() wml = doc.createElement("wml") doc.appendChild(wml) property = doc.createElement("property") wml.appendChild(property) descriptionNode = doc.createElement("description") property.appendChild(descriptionNode) descriptionText = doc.createTextNode(description.decode('ISO-8859-1')) descriptionNode.appendChild(descriptionText) file = codecs.open('contentFinal.xml', 'w', encoding='ISO-8859-1') file.write(doc.toprettyxml()) file.close() </code></pre> <p>The description node contains some characters in <code>ISO-8859-1 encoding</code>, this is encoding specified by the site it self in meta tag. But when <code>doc.toprettyxml()</code> starts writing in file I got following error:</p> <pre><code>Traceback (most recent call last): File "main.py", line 467, in &lt;module&gt; file.write(doc.toprettyxml()) File "C:\Python27\lib\xml\dom\minidom.py", line 60, in toprettyxml return writer.getvalue() File "C:\Python27\lib\StringIO.py", line 271, in getvalue self.buf += ''.join(self.buflist) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 10: ordinal not in range(128) </code></pre> <p>Why am I getting this error as I am decoding and encoding with same standard?</p> <p><strong>Edited</strong></p> <p>I have following deceleration in my script file:</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- </code></pre> <p>may be this is conflicting?</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