Author msapiro
Recipients Johannes Löthberg, barry, cheryl.sabella, diekhans, edeca, maciej.szulik, matrixise, msapiro, r.david.murray
Date 2020-10-06.02:54:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601952878.37.0.95144188272.issue27321@roundup.psfhosted.org>
In-reply-to
Content
I work around it with
```
class Message(email.message.Message):

    def as_string(self):
        # Work around for https://bugs.python.org/issue27321 and
        # https://bugs.python.org/issue32330.
        try:
            value = email.message.Message.as_string(self)
        except (KeyError, LookupError, UnicodeEncodeError):
            value = email.message.Message.as_bytes(self).decode(
                'ascii', 'replace')
        # Also ensure no unicode surrogates in the returned string.
        return email.utils._sanitize(value)
```
This is easy for me because it's Mailman which already subclasses email.message.Message for other reasons. It is perhaps more difficult if you aren't already subclassing email.message.Message for other purposes.
History
Date User Action Args
2020-10-06 02:54:38msapirosetrecipients: + msapiro, barry, diekhans, r.david.murray, maciej.szulik, matrixise, cheryl.sabella, Johannes Löthberg, edeca
2020-10-06 02:54:38msapirosetmessageid: <1601952878.37.0.95144188272.issue27321@roundup.psfhosted.org>
2020-10-06 02:54:38msapirolinkissue27321 messages
2020-10-06 02:54:38msapirocreate