osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unicode (was: Old Man Yells At Cloud)


On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall <leamhall at gmail.com> wrote:
> Still trying to keep this Py2 and Py3 compatible.
>
> The Py2 error is:
>         UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6'
>         in position 8: ordinal not in range(128)
>
> even when the string is manually converted:
>         name    = unicode(self.name)
>
> Same sort of issue with:
>         name    = self.name.decode('utf-8')
>
>
> Py3 doesn't like either version.

You got a Unicode *EN*code error when you tried to *DE* code. That's a
quirk of Py2's coercion behaviours, so the error's a bit obscure, but
it means that you (most likely) actually have a Unicode string
already. Check what type(self.name) is, and see if the problem is
actually somewhere else.

(It's hard to give more specific advice based on this tiny snippet, sorry.)

ChrisA