<html>
<body>
At 08:12 PM 2/27/2011, you wrote:<br>
<blockquote type=cite class=cite cite="">On 28/02/2011 01:31, Laurent
Duchesne wrote:<br>
<blockquote type=cite class=cite cite="">Hi,<br><br>
I'm using python 3.2 and got the following error:<br><br>
<blockquote type=cite class=cite cite="">
<blockquote type=cite class=cite cite="">
<blockquote type=cite class=cite cite="">nntpClient =
nntplib.NNTP_SSL(...)<br>
nntpClient.group("alt.binaries.cd.lossless")<br>
nntpClient.over((534157,534157))</blockquote></blockquote></blockquote>
... 'subject': 'Myl\udce8ne Farmer - Anamorphosee (Japan Edition)
1995<br>
[02/41] "Back.jpg" yEnc (1/3)' ...<br>
<blockquote type=cite class=cite cite="">
<blockquote type=cite class=cite cite="">
<blockquote type=cite class=cite cite="">overview =
nntpClient.over((534157,534157))<br>
print(overview[1][0][1]['subject'])</blockquote></blockquote></blockquote>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce8' in<br>
position 3: surrogates not allowed<br><br>
I'm not sure if I should report this as a bug in nntplib or if I'm
doing<br>
something wrong.<br><br>
Note that I get the same error if I try to write this data to a
file:<br><br>
<blockquote type=cite class=cite cite="">
<blockquote type=cite class=cite cite="">
<blockquote type=cite class=cite cite="">h = open("output.txt",
"a")<br>
h.write(overview[1][0][1]['subject'])</blockquote></blockquote>
</blockquote>Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce8' in<br>
position 3: surrogates not allowed<br>
</blockquote>It's looks like the subject was originally encoded as
Latin-1 (or<br>
similar) (b'Myl\xe8ne Farmer - Anamorphosee (Japan Edition) 1995<br>
[02/41] "Back.jpg" yEnc (1/3)') but has been decoded as UTF-8
with<br>
"surrogateescape" passed as the "errors"
parameter.</blockquote><br>
3.2 Docs<br>
  6.6. codecs — Codec registry and base classes<br>
    Possible values for errors are<br>
      'surrogateescape': replace with surrogate
U+DCxx, see PEP 383 <br><br>
Yes, it would have been 0xE8 -  <b>Mylène</b> <br><br>
Googling on surrogateescape I can see lots of argument about unintended
outcomes....  yikes!<br><br>
<blockquote type=cite class=cite cite="">You can get the
"correct" Unicode by encoding as UTF-8 with<br>
"surrogateescape" and then decoding as Latin-1:<br><br>
    overview[1][0][1]['subject'].encode("utf-8",
"surrogateescape").decode("latin-1")</blockquote>
</body>
</html>