Skip to content

Failure when calling __str__ for MIMEBase(message, rfc822) objects #45897

Closed

Description

@hsp
mannequin
BPO 1556
Nosy @facundobatista
Files
  • MimebaseError.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-06-21.21:12:41.230>
    created_at = <Date 2007-12-05.15:51:16.608>
    labels = ['invalid', 'library', 'type-crash']
    title = 'Failure when calling __str__ for MIMEBase(message, rfc822) objects'
    updated_at = <Date 2008-06-21.21:12:41.229>
    user = 'https://bugs.python.org/hsp'

    bugs.python.org fields:

    activity = <Date 2008-06-21.21:12:41.229>
    actor = 'facundobatista'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-06-21.21:12:41.230>
    closer = 'facundobatista'
    components = ['Library (Lib)']
    creation = <Date 2007-12-05.15:51:16.608>
    creator = 'hsp'
    dependencies = []
    files = ['8879']
    hgrepos = []
    issue_num = 1556
    keywords = []
    message_count = 3.0
    messages = ['58216', '68542', '68546']
    nosy_count = 3.0
    nosy_names = ['facundobatista', 'hsp', 'elachuni']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue1556'
    versions = ['Python 2.6', 'Python 2.5']

    Activity

    1. hsp commented on Dec 5, 2007

      hspmannequin
      MannequinAuthor

      When creating a MIMEBase object with message/rfc822 mimetype invoking
      the objects __str__ method results in an exception.
      Even if this behaviour should be intended the error message "TypeError:
      Expected list, got <type 'str'>" is not helpful.
      To reproduce the problem run the attached script after creating the file
      'test.eml' in the script's directory.

          mimetype = mimetypes.guess_type(filename)[0]
          maintype, subtype = mimetype.split('/')
          attachment = MIMEBase(maintype, subtype)
          attachment.set_payload(file(filename).read( ))
          print attachment
      #python MimebaseError.py                                               
                                                                             
                   [1]
      message/rfc822
      Traceback (most recent call last):
        File "MimebaseError.py", line 19, in <module>
          main()
        File "MimebaseError.py", line 16, in main
          print attachment
        File "email/message.py", line 116, in __str__
        File "email/message.py", line 131, in as_string
        File "email/generator.py", line 84, in flatten
        File "email/generator.py", line 109, in _write
        File "email/generator.py", line 135, in _dispatch
        File "email/generator.py", line 266, in _handle_message
        File "email/message.py", line 185, in get_payload
      TypeError: Expected list, got <type 'str'>
    2. added
      stdlib
      type-crash
      on Dec 5, 2007
    3. elachuni commented on Jun 21, 2008

      elachunimannequin
      Mannequin

      I don't really think the MIMEBase class is supposed to be used like
      this, or at all: it behaves more like a Multipart message in that it
      expects to carry a list of MIMEBase objects as a payload (not a string!)
      though it doesn't define a boundary by default.

      You can carry on using the MIMEBase class, but changing the line that says:

      attachment.set_payload(file(filename).read( ))
      

      for:

      attachment.set_payload([MIMEText(file(filename).read())])
      

      I'd recommend you to use:

          attachment = Message()
          attachment.set_payload(file(filename).read())

      or if you want a multipart message:

          attachment = MIMEMultipart()
          text = MIMEText(file(filename).read())
          attachment.attach(text)
    4. facundobatista commented on Jun 21, 2008

      @facundobatista
      Member

      I agree with Anthony. If you have any further questions regarding how to
      use this library feel free to ask them in python-list.

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-crash

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions