Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hsp mannequin opened this issue Dec 5, 2007 · 3 comments
Closed

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

hsp mannequin opened this issue Dec 5, 2007 · 3 comments
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@hsp
Copy link
Mannequin

hsp mannequin commented Dec 5, 2007

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']

    @hsp
    Copy link
    Mannequin Author

    hsp mannequin commented Dec 5, 2007

    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'>

    @hsp hsp mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 5, 2007
    @elachuni
    Copy link
    Mannequin

    elachuni mannequin commented Jun 21, 2008

    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)

    @facundobatista
    Copy link
    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant