Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

string payload expected: <type 'list'> error

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


ramdaz at gmail

Nov 26, 2009, 11:57 AM

Post #1 of 6 (378 views)
Permalink
string payload expected: <type 'list'> error

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
--
http://mail.python.org/mailman/listinfo/python-list


python at mrabarnett

Nov 26, 2009, 12:33 PM

Post #2 of 6 (366 views)
Permalink
Re: string payload expected: <type 'list'> error [In reply to]

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)

--
http://mail.python.org/mailman/listinfo/python-list


ramdaz at gmail

Nov 26, 2009, 12:49 PM

Post #3 of 6 (363 views)
Permalink
Re: string payload expected: <type 'list'> error [In reply to]

On Nov 27, 1:33 am, MRAB <pyt...@mrabarnett.plus.com> 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 .....
--
http://mail.python.org/mailman/listinfo/python-list


lie.1296 at gmail

Nov 26, 2009, 1:39 PM

Post #4 of 6 (362 views)
Permalink
Re: string payload expected: <type 'list'> error [In reply to]

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?
--
http://mail.python.org/mailman/listinfo/python-list


ramdaz at gmail

Nov 27, 2009, 1:43 AM

Post #5 of 6 (346 views)
Permalink
Re: string payload expected: <type 'list'> error [In reply to]

On Nov 27, 2:39 am, Lie Ryan <lie.1...@gmail.com> 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
--
http://mail.python.org/mailman/listinfo/python-list


lie.1296 at gmail

Nov 29, 2009, 7:55 AM

Post #6 of 6 (330 views)
Permalink
Re: string payload expected: <type 'list'> error [In reply to]

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).
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.