I am trying to encode a binary with MIMEApplication in Python 3.3, as part of a multi-threaded MIME HTTP POST. I have a problem that the character 0x0d is interpreted as a new string 0xa, despite the fact that everything is set to binary bytes.
Here's a minimal test case with a binary string with 0x0d in it that got the wrong interpretation:
from email.encoders import encode_noop
from email.generator import BytesGenerator
from email.mime.application import MIMEApplication
import io
app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop)
b = io.BytesIO()
g = BytesGenerator(b)
g.flatten(app)
for i in b.getvalue()[-3:]:
print("%02x " % i, end="")
print()
Exit: 51 0a 51when it should be51 0d 51
Note that this is necessary to create the binary part for the multi-page HTTP POST message.
Nils source
share