Validation error with non-ascii characters not printed in Python 2.7
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Invalid
|
Undecided
|
scoder |
Bug Description
When validating an element against an enumeration of values that contains non-ascii characters fails, the exception fails to show the error. This only happens in Python 2.
Test script (also added as attachment):
# -*- coding: utf-8 -*-
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from lxml import etree
if __name__ == '__main__':
xml = StringIO(
f = StringIO('''\
<xsd:schema xmlns:xsd="http://
<xsd:element name="status">
</xsd:element>
</xsd:schema>
''')
xmlschema_doc = etree.parse(f)
xmlschema = etree.XMLSchema
doc = etree.parse(xml)
xmlschema.
Tested in Python 2.7.14:
Traceback (most recent call last):
File "lxml_ascii_
xmlschema.
File "src/lxml/
lxml.etree.
Tested in Python 3.6.0:
Traceback (most recent call last):
File "lxml_ascii_
xmlschema.
File "src/lxml/
lxml.etree.
Environment:
Python : sys.version_
lxml.etree : (4, 2, 3, 0)
libxml used : (2, 9, 8)
libxml compiled : (2, 9, 8)
libxslt used : (1, 1, 32)
libxslt compiled : (1, 1, 32)
This is due to a bug in Cython's f-string formatting code that used PyObject_Str() instead of PyObject_Unicode() for normal string formatting. It's been fixed there. The next lxml release should have it.