string payload expected: <type 'list'> error

Discussion in 'Python' started by Ramdas, Nov 26, 2009.

  1. Ramdas

    Ramdas Guest

    Dear all,

    I believe this is an error which was fixed in Python 2.3 itself. But I
    am running Python 2,5.2 and error keeps on cropping up.

    Here is my code to construct emails . It works perfectly when I dont
    have any attachments. Please find my code at

    http://dpaste.com/hold/125574/


    However when I try constructing with attachments it crashes with this
    error string payload expected: <type 'list'> error.

    Going through the trace error I discover that as I call the function
    msg.as_string, the function . _handle_text(self, msg) expects a string
    object but I am generating list object. Can someone advise what I need
    to code to parse series of attachments into an email.

    Help appreciated
     
    Ramdas, Nov 26, 2009
    #1
    1. Advertising

  2. Ramdas

    MRAB Guest

    Ramdas wrote:
    > Dear all,
    >
    > I believe this is an error which was fixed in Python 2.3 itself. But I
    > am running Python 2,5.2 and error keeps on cropping up.
    >
    > Here is my code to construct emails . It works perfectly when I dont
    > have any attachments. Please find my code at
    >
    > http://dpaste.com/hold/125574/
    >
    >
    > However when I try constructing with attachments it crashes with this
    > error string payload expected: <type 'list'> error.
    >
    > Going through the trace error I discover that as I call the function
    > msg.as_string, the function . _handle_text(self, msg) expects a string
    > object but I am generating list object. Can someone advise what I need
    > to code to parse series of attachments into an email.
    >
    > Help appreciated


    I've been looking at the example in the Python 2.6.2 documentation. It
    looks like you should have:

    msg1.add_header('Content-Disposition', 'attachment', filename=filename)
     
    MRAB, Nov 26, 2009
    #2
    1. Advertising

  3. Ramdas

    Ramdas Guest

    On Nov 27, 1:33 am, MRAB <> wrote:
    > Ramdas wrote:
    > > Dear all,

    >
    > > I believe this is an error which was fixed in Python 2.3 itself. But I
    > > am running Python 2,5.2 and error keeps on cropping up.

    >
    > > Here is my code to construct emails . It works perfectly when I dont
    > > have any attachments. Please find my code at

    >
    > >http://dpaste.com/hold/125574/

    >
    > > However when I try constructing with attachments it crashes with this
    > > error string payload expected: <type 'list'> error.

    >
    > > Going through the trace error I discover that as I call the function
    > > msg.as_string, the function . _handle_text(self, msg) expects a string
    > > object but I am generating list object. Can someone advise what I need
    > > to code to parse series of attachments into an email.

    >
    > > Help appreciated

    >
    > I've been looking at the example in the Python 2.6.2 documentation. It
    > looks like you should have:
    >
    >      msg1.add_header('Content-Disposition', 'attachment', filename=filename)


    Thanks! I did that correction, however the error still persists .....
     
    Ramdas, Nov 26, 2009
    #3
  4. Ramdas

    Lie Ryan Guest

    Ramdas wrote:
    > Dear all,
    >
    > I believe this is an error which was fixed in Python 2.3 itself. But I
    > am running Python 2,5.2 and error keeps on cropping up.
    >
    > Here is my code to construct emails . It works perfectly when I dont
    > have any attachments. Please find my code at
    >
    > http://dpaste.com/hold/125574/
    >
    >
    > However when I try constructing with attachments it crashes with this
    > error string payload expected: <type 'list'> error.


    Except if the traceback is due to a recursive function that doesn't
    terminate, please always post the FULL traceback. Don't summarize the
    error message.

    > Going through the trace error I discover that as I call the function
    > msg.as_string, the function . _handle_text(self, msg) expects a string
    > object but I am generating list object. Can someone advise what I need
    > to code to parse series of attachments into an email.
    >
    > Help appreciated


    I smell this part of the code as particularly fishy:

    msg1 = MIMEBase(maintype, subtype)
    msg1.set_payload(MIMEText(fp.read()))

    why are you wrapping a MIMEText inside a MIMEBase?
     
    Lie Ryan, Nov 26, 2009
    #4
  5. Ramdas

    Ramdas Guest

    On Nov 27, 2:39 am, Lie Ryan <> wrote:
    > Ramdas wrote:
    > > Dear all,

    >
    > > I believe this is an error which was fixed in Python 2.3 itself. But I
    > > am running Python 2,5.2 and error keeps on cropping up.

    >
    > > Here is my code to construct emails . It works perfectly when I dont
    > > have any attachments. Please find my code at

    >
    > >http://dpaste.com/hold/125574/

    >
    > > However when I try constructing with attachments it crashes with this
    > > error string payload expected: <type 'list'> error.

    >
    > Except if the traceback is due to a recursive function that doesn't
    > terminate, please always post the FULL traceback. Don't summarize the
    > error message.
    >
    > > Going through the trace error I discover that as I call the function
    > > msg.as_string, the function . _handle_text(self, msg) expects a string
    > > object but I am generating list object. Can someone advise what I need
    > > to code to parse series of attachments into an email.

    >
    > > Help appreciated

    >
    > I smell this part of the code as particularly fishy:
    >
    > msg1 = MIMEBase(maintype, subtype)
    > msg1.set_payload(MIMEText(fp.read()))
    >
    > why are you wrapping a MIMEText inside a MIMEBase?


    I tried with MIMEBASE but it still fails...... I changed it to
    MIMEText, hoping that might trick __handletext to think its a string
    Anyway that also doesn't work.

    Any ideas
     
    Ramdas, Nov 27, 2009
    #5
  6. Ramdas

    Lie Ryan Guest

    On 11/27/2009 8:43 PM, Ramdas wrote:
    > I tried with MIMEBASE but it still fails...... I changed it to
    > MIMEText, hoping that might trick __handletext to think its a string
    > Anyway that also doesn't work.
    >


    just pass the string directly to MIMEBase.set_payload:

    fp = open('...')
    msg1 = MIMEBase(maintype, subtype)
    msg1.set_payload(fp.read())

    either that or use a more specialized subclass of MIMEBase (e.g. MIMEText).
     
    Lie Ryan, Nov 29, 2009
    #6
    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. junaid

    JMF: encrypting rtp payload

    junaid, Dec 30, 2003, in forum: Java
    Replies:
    0
    Views:
    438
    junaid
    Dec 30, 2003
  2. zhengyu

    access HTTP payload in Java

    zhengyu, Feb 11, 2004, in forum: Java
    Replies:
    4
    Views:
    4,561
    Andy Fish
    Feb 12, 2004
  3. andrew blah
    Replies:
    6
    Views:
    737
    M.E.Farmer
    Oct 16, 2004
  4. brad

    post xml payload with urllib

    brad, Aug 14, 2007, in forum: Python
    Replies:
    1
    Views:
    644
  5. Jon Sargeant

    Floating-Point Constant with Payload

    Jon Sargeant, Apr 20, 2008, in forum: C Programming
    Replies:
    1
    Views:
    314
    Barry Schwarz
    Apr 20, 2008
Loading...

Share This Page