In message.py we have from __future__ import unicode literals. This is the reason I had to encode strings back into ASCII here, although I didn't realize it at the time.
However, 'Content-Type' and 'attachment' headers are both Unicode strings due to the import statement at the top of the filer. Since add_header() eventually joins all the arguments and the type of joining a Unicode literal and an ASCII literal in Python 2.7 is a Unicode string, the result is a Unicode string.
As referenced in the documentation, get_param() and email.utils.collapse_rfc2231_value() are inverses. But in Python 2.7, get_param() returns a Unicode string due to the above issue and collapse_rfc2231_value() requires an ASCII string, you get an error.
I think this could be fixed by encoding the fixed strings here and here as ASCII.
In
message.py
we havefrom __future__ import unicode literals
. This is the reason I had to encode strings back into ASCII here, although I didn't realize it at the time.However,
'Content-Type'
and'attachment'
headers are both Unicode strings due to the import statement at the top of the filer. Sinceadd_header()
eventually joins all the arguments and the type of joining a Unicode literal and an ASCII literal in Python 2.7 is a Unicode string, the result is a Unicode string.As referenced in the documentation,
get_param()
andemail.utils.collapse_rfc2231_value()
are inverses. But in Python 2.7,get_param()
returns a Unicode string due to the above issue andcollapse_rfc2231_value()
requires an ASCII string, you get an error.I think this could be fixed by encoding the fixed strings here and here as ASCII.