3.2: email.message.get_payload() delivers str, but send_message expectbytes

A

Axel Rau

Hi all,

I'm just starting with imaplib, email and smtplib and try to write a
SPAM reporter. I retrieve SPAM mails from an IMAP server and add them as
message/rfc822 attachments to a report mail.
Sometimes my call of smtplib.send_message works, sometimes, I get:
----------
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py",
line 771, in send_message
rcpt_options)
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py",
line 739, in sendmail
(code,resp) = self.data(msg)
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py",
line 495, in data
q = _quote_periods(msg)
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/smtplib.py",
line 165, in _quote_periods
return re.sub(br'(?m)^\.', '..', bindata)
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/re.py",
line 167, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: sequence item 1: expected bytes, str found
----------
When I query the class of my pyloads, they always show up as strings.
The test case, which always fails is an oversized SPAM, which my script
must truncate. I do this by removing MIME parts from the end (just
deleting items from the list, describing the multipart structure).

Another problem comes up, when I try to encode the payload of the whole
report mail, I get always:
-------
File "erdb_bt.py", line 195, in flushReports
email.encoders.encode_base64(self.msg)
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/email/encoders.py",
line 32, in encode_base64
encdata = str(_bencode(orig), 'ascii')
File
"/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/base64.py",
line 56, in b64encode
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
TypeError: expected bytes, not list
 
A

Axel Rau

line 167, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: sequence item 1: expected bytes, str found
I just filed issue 11837.

Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top