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

Discussion in 'Python' started by Axel Rau, Apr 8, 2011.

  1. Axel Rau

    Axel Rau Guest

    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
    -------
    What am I doing wrong?

    Axel
     
    Axel Rau, Apr 8, 2011
    #1
    1. Advertising

  2. Axel Rau

    Axel Rau Guest

    Re: 3.2: email.message.get_payload() delivers str, but send_messageexpect bytes

    On 08.04.11 13:43, Axel Rau wrote:
    > 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
     
    Axel Rau, Apr 12, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chuck amadi
    Replies:
    1
    Views:
    378
    Piet van Oostrum
    Jun 23, 2004
  2. chuck amadi
    Replies:
    0
    Views:
    352
    chuck amadi
    Jun 22, 2004
  3. Chuck Amadi
    Replies:
    0
    Views:
    528
    Chuck Amadi
    Jun 22, 2004
  4. lrotger
    Replies:
    0
    Views:
    463
    lrotger
    Jul 3, 2006
  5. dpapathanasiou
    Replies:
    6
    Views:
    1,061
    dpapathanasiou
    Oct 14, 2009
Loading...

Share This Page