title: XML write to file UnicodeDecodeError Python 2.7.3
body: <p>I've searched the site and haven't found an answer that works for me. My problem is that I'm trying to write xml to a file and when I run the script from the terminal I get:</p>
  
  <pre><code>Traceback (most recent call last):
  File "fetchWiki.py", line 145, in &lt;module&gt;
  pageDictionary = qSQL(users_database)
  File "fetchWiki.py", line 107, in qSQL
  writeXML(listNS)
  File "fetchWiki.py", line 139, in writeXML
  f1.write(doc.toprettyxml(indent="\t", encoding="utf-8"))       
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 57, in toprettyxml
  self.writexml(writer, "", indent, newl, encoding)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1751, in writexml
  node.writexml(writer, indent, addindent, newl)
  ----//---- more lines in here ----//----
  self.childNodes[0].writexml(writer, '', '', '')
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1040, in writexml
  _write_data(writer, "%s%s%s" % (indent, self.data, newl))
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 297, in _write_data
  writer.write(data)
  File "/usr/lib/python2.7/codecs.py", line 351, in write
  data, consumed = self.encode(object, self.errors)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1176: ordinal not
  in range(128)
  </code></pre>
  
  <p>This is from the following code:</p>
  
  <pre><code>doc = Document()
  
  base = doc.createElement('Wiki')
  doc.appendChild(base)
  
  for ns_dict in listNamespaces: 
      namespace = doc.createElement('Namespace')
      base.appendChild(namespace)
      namespace.setAttribute('NS', ns_dict)
  
      for title in listNamespaces[ns_dict]:
  
          page = doc.createElement('Page')
          try:
              title.encode('utf8')
              page.setAttribute('Title', title)
          except:
              newTitle = title.decode('latin1', 'ignore')
              newTitle.encode('utf8', 'ignore')
              page.setAttribute('Title', newTitle)
  
          namespace.appendChild(page)
          text = doc.createElement('Content')
          text_content = doc.createTextNode(listNamespaces[ns_dict][title])
          text.appendChild(text_content)
          page.appendChild(text)
  
      f1  = open('pageText.xml', 'w')
      f1.write(doc.toprettyxml(indent="\t", encoding="utf-8"))       
      f1.close()
  </code></pre>
  
  <p>With or without the encode / decode 'igonore' parameter the error occurs. 
  Adding</p>
  
  <pre><code># -*- coding: utf-8 -*- 
  </code></pre>
  
  <p>does not  help. </p>
  
  <p>I created the python document using Eclipse with Pydoc and it works fine with no problems, but when I run it from the terminal it errors. </p>
  
  <p>Any help is much appreciated including links to answers I did not find.</p>
  
  <p>Thanks.</p>