[issue7045] utf-8 encoding error
report at bugs.python.org
Sat Oct 3 12:22:01 CEST 2009
Ezio Melotti <ezio.melotti at gmail.com> added the comment:
I can't reproduce it either on Ubuntu 9.04 32-bit. I tried both from the
terminal and from the file, using Py3.2a0.
As Martin said, the fact that in narrow builds of Python the codepoints
outside the BMP are represented with two surrogate pairs is a known
"issue". This is how UTF-16 works, even if it has some problematic
In your example 'line' is not equal to 'first' because line is the
codepoint of the first surrogate and 'first' is a scalar value that
represents the SHAVIAN LETTER TOT (U+010451).
Regarding the traceback you pasted in the first post, have you used
print('𐑑') or print(line)?
This is what I get using line:
>>> line = '𐑑𐑧𐑕𐑑𐑦𐑙'
>>> first = '𐑑'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud801' in
position 0: surrogates not allowed
In this case you are getting an error because lone surrogates are
invalid and they can't be encoded. If you use line[:2] instead it works
because it takes both the surrogates:
>>> first == line[0:2]
If you really got that error with print('𐑛'), then #3297 could be related.
Can you also try this and see what it prints?
>>> import sys
priority: -> normal
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list