From: Peter Otten on
Lie Ryan wrote:

> On 01/12/10 23:50, Jens Müller wrote:
>>> To convert unicode into str you have to *encode()* it.
>>>
>>> u"...".decode(...) will implicitly convert to ASCII first, i. e. is
>>> equivalent to
>>>
>>> u"...".encode("ascii").decode(...)
>>>
>>> Hence the error message
>>
>> Ah - yes of course.
>>
>> And how can you use the system's default encoding with errors=ignore?
>> The default encoding is the one that is used if no parameters are given
>> to "encode".
>>
>> Thanks again!
>
>
>>>> import sys
>>>> sys.getdefaultencoding()
> 'ascii'
>>>> u'M\xfcnchen, pronounced
> [\u02c8m\u028fn\xe7\u0259n]'.encode(sys.getdefaultencoding(), 'ignore')
> 'Mnchen, pronounced [mnn]'
>
>
> unless this is for debugging, I doubt ignoring error in this particular
> case is an acceptable solution (how do you pronounce [mnn]?)

Also, I think on most systems

>>> sys.getdefaultencoding()
'ascii'

You might try

>>> locale.getpreferredencoding()
'UTF-8'

instead.

Peter