Message10367

Author pekka.klarck
Recipients pekka.klarck
Date 2015-10-21.08:45:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1445417150.72.0.990884776188.issue2413@psf.upfronthosting.co.za>
In-reply-to
Content
This seems to be a variation of #1479. To reproduce:

E:\>jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) Client VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.etree import ElementTree as ET
>>> elem = ET.XML('<test/>')
>>> tree = ET.ElementTree(elem)
>>> tree.write('test.xml', encoding='blaaaah')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 818, in write
    qnames, namespaces = _namespaces(
  File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 886, in _namespaces
    add_qname(tag)
  File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 870, in add_qname
    qnames[qname] = encode(qname)
  File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 870, in add_qname
    qnames[qname] = encode(qname)
  File "C:\jython2.7.0\Lib\xml\etree\ElementTree.py", line 845, in encode
    return text.encode(encoding)
LookupError: unknown encoding 'blaaaah'
>>> import os
>>> os.remove('test.xml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: unlink(): an unknown error occurred: E:\test.xml


A workaround is opening and closing output files explicitly:

    with open('test.xml', 'wb') as output:
        tree.write(output, ...)
History
Date User Action Args
2015-10-21 08:45:50pekka.klarcksetrecipients: + pekka.klarck
2015-10-21 08:45:50pekka.klarcksetmessageid: <1445417150.72.0.990884776188.issue2413@psf.upfronthosting.co.za>
2015-10-21 08:45:50pekka.klarcklinkissue2413 messages
2015-10-21 08:45:49pekka.klarckcreate