A piece of code that works with Python 2 does not work with Python 3 on my system.
f = open("plotwidget.svg")
svgData = f.read()
xml_stream = QtCore.QXmlStreamReader(svgData)
This raises the following error:
UnicodeEncodeError 'latin-1' codec can't encode character '\u2212' in position 12688: ordinal not in range(256)
The character is indeed not an ASCII character, but I don't understand why QXmlStreamReader
expects to find a latin-1
encoding when the file seems to be a proper UTF-8 file with the encoding specified in the header.
The SVG file was generated with matplotlib
(figure.savefig(...)
).
The problem is caused because the constructor requires bytes and not strings, the solution is to use
encode()
.