content-typetext/plaincharset="iso- - content-transfer-encodingquoted-printable = in factthe text message object doesn' check to see that the data you're mimeencoding is valid per unicode in general--we can send invalid utf text but the receiver may have trouble decoding itm mimetext( ' \xe '_charset='utf- 'print(mcontent-typetext/plaincharset="utf- mime-version content-transfer-encodingbase qerc ' \xe bdecode('utf 'unicodedecodeerror'utf codec can' decode bytes in position - unexpected import base base decode( 'qerc' ' \xe bbase decode( 'qerc'decode('utf'unicodedecodeerror'utf codec can' decode bytes in position - unexpected so what to do if we need to attach message text to composed messages if the text' datatype requirement is indirectly dictated by its unicode encoding namethe generic message superclass doesn' help here directly if we specify an encodingas it exhibits the same encoding-specific behaviorm message( set_payload('spam'charset='us-ascii'print(mmime-version content-typetext/plaincharset="us-asciicontent-transfer-encoding bit spam message( set_payload( 'spam'charset='us-ascii'attributeerror'bytesobject has no attribute 'encodem set_payload('spam'charset='utf- 'typeerrormust be bytes or buffernot str although we could try to work around these issues by repeating much of the code that email runsthe redundancy would make us hopelessly tied to its current implementation and dependent upon its future changes the followingfor exampleparrots the steps that email runs internally to create text message object for ascii encoding textunlike the mimetext classthis approach allows all data to be read from files as binary byte stringseven if it' simple ascii client-side scripting