On 2015-12-11, Peter Otten wrote: > Adam Funk wrote:
>> but with either or both of those, I get the dreaded >> "UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position >> 562: ordinal not in range(128)". How can I force the output to be in >> UTF-8 & silently suppress invalid characters? > > (I'm assuming you are using Python 2 and that main_body is a unicode > instance) The short answer turned out to be 'switch to Python 3', which I think is what I'll do from now on unless I absolutely need a library that isn't available there. (AFAICT, the email parser in 2.7 returns the body as a bytestring & doesn't actually look at the Content-Type header, & trying to decode the body with that just made it barf in different places.) -- Science is what we understand well enough to explain to a computer. Art is everything else we do. --- Donald Knuth -- https://mail.python.org/mailman/listinfo/python-list