Please do not reply directly to this email. All additional
comments should be made in the comments box of this bug.
https://bugzilla.redhat.com/show_bug.cgi?id=668282
--- Comment #29 from James Antill <james.antill(a)redhat.com> 2011-10-20 12:18:28 EDT
---
So, if we debug this a little, we find that the clause:
if not isinstance(name, unicode)
...fails in _to_unicode(), so it basically looks like yum is sending us a
string that purports to be unicode, but contains invalid encoding.
I'll try and help, as I have to deal with this confusion a lot in yum. What
Zdeněk said is correct ... if the thing you have is "isinstance(name, unicode)"
then you should think of it as a unicode object, it "can't" be bad they are
all
the same etc.
To double check, if we do:
print name.decode('utf-8')
... we get "Error Value: 'ascii' codec can't encode character
u'\xe9' in
position 23: ordinal not in range(128)"
One, _very_, confusing thing is that both str() and unicode() objects have
.decode() and .encode() methods ... and coming from the C world I tend to think
of "utf-8" as the natural type which should be encoded to python's internal
"unicode" object, but that's exactly the opposite of what you should do.
This also means you can do:
"â…“" (fine a bytes object with utf-8 in it)
"â…“".decode('utf-8') (also fine, but now a unicode object)
"â…“".decode('utf-8').decode('utf-8') (raises: UnicodeEncodeError:
'ascii' codec
can't encode character u'\u2153' in position 0: ordinal not in range(128)).
...which is nice.
Which is why we use to_unicode() and to_utf8() everywhere in yum.
The last bit, which is likely where the error is coming from is that (because
python defaults to the ascii codec):
"â…“" + "a" (fine)
"a" + "â…“" (fine)
"â…“".decode('utf-8') + "a" (fine)
"a" + "â…“".decode('utf-8') (fine)
"â…“".decode('utf-8') + "â…“".decode('utf-8') (fine)
"â…“".decode('utf-8') + "â…“" (raises)
"a".decode('utf-8') + "â…“" (raises)
--
Configure bugmail:
https://bugzilla.redhat.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.