mailtools package of this (example - because it is used by email to encode from bytes to text at initialization timeit is able to decode to ascii text per unicode as an extra stepafter running the original call to perform base encoding and arrange content-encoding headers the fact that email does not do this extra unicode decoding step itself is genuine bug in that package (albeitone introduced by changes elsewhere in python standard libraries)but the workaround does its jobin mailtools mailsender module ahead in this def fix_encode_base (msgobj)from email encoders import encode_base encode_base (msgobjwhat email does normallyleaves bytes bytes msgobj get_payload(bytes fails in email pkg on text gen text bytes decode('ascii'decode to unicode str so text gen works line splitting logic omitted msgobj set_payload('\njoin(lines)from email mime image import mimeimage from mailtools mailsender import fix_encode_base bytes open('monkeys jpg''rb'read( mimeimage(bytes_encoder=fix_encode_base print( as_string()[: ]content-typeimage/jpeg mime-version content-transfer-encodingbase use custom workaround convert to ascii str / / aaqskzjrgabaqeaeab aad/ wbdaaibaqibaqicagicagicawudawmdawyebamfbwyhbwcg bwcicqsjcagkcachcg kcgsmdawmbwkodw mdgsmdaz/ wbdaqicagmdawydawymcacidawmdawm dawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdaz/waarcahoavqdasia ahebaxeb/ qahwaaaqubaqebaqeaaaaaaaaaaaecawqfbgcicqol/ qatraaagedawieawufbaqa aaf aqidaaqrbrihmuege fhbyjxfdkbkaeii kxwrvs fakm jyggkkfhcygroljicokso nty odk rfrkdisuptvfvwv hzwmnkzwznaglqc print(mto print the entire messagevery long another possible workaround involves defining custom mimeimage class that is like the original but does not attempt to perform base ending on creationthat waywe could encode and translate to str before message object creationbut still make use of the original class' header-generation logic if you take this routethoughyou'll find that it requires repeating (reallycutting and pastingfar too much of the original logic to be reasonable--this repeated code would have to mirror any future email changesfrom email mime nonmultipart import mimenonmultipart class myimage(mimenonmultipart)def __init__(selfimagedatasubtype)mimenonmultipart __init__(self'image'subtypeself set_payload(_imagedatarepeat all the base logic herewith an extra ascii unicode decode myimage(text_from_bytesinterestinglythis regression in email actually reflects an unrelated change in python' base module made in which was completely benign until the python bytes client-side scripting