Hi all, [This is a repost from comp.lang.python]
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 truncates. 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 ------- What am I doing wrong? Axel --- PGP-Key:29E99DD6 ☀ +49 151 2300 9283 ☀ computing @ chaos claudius _______________________________________________ Email-SIG mailing list Email-SIG@python.org Your options: http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com