Another 2 to 3 mail encoding problem

Terry Reedy tjreedy at udel.edu
Wed Aug 26 13:58:49 EDT 2020


On 8/26/2020 11:10 AM, Chris Green wrote:

> I have a simple[ish] local mbox mail delivery module as follows:-
...
> It has run faultlessly for many years under Python 2.  I've now
> changed the calling program to Python 3 and while it handles most
> E-Mail OK I have just got the following error:-
> 
>      Traceback (most recent call last):
>        File "/home/chris/.mutt/bin/filter.py", line 102, in <module>
>          mailLib.deliverMboxMsg(dest, msg, log)
...
>        File "/usr/lib/python3.8/email/generator.py", line 406, in write
>          self._fp.write(s.encode('ascii', 'surrogateescape'))
>      UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128)

'\ufeff' is the Unicode byte-order mark.  It should not be present in an 
ascii-only 3.x string and would not normally be present in general 
unicode except in messages like this that talk about it.  Read about it, 
for instance, at
https://en.wikipedia.org/wiki/Byte_order_mark

I would catch the error and print part or all of string s to see what is 
going on with this particular message.  Does it have other non-ascii chars?


-- 
Terry Jan Reedy



More information about the Python-list mailing list