Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > string payload expected: <type 'list'> error

Reply
Thread Tools

string payload expected: <type 'list'> error

 
 
Ramdas
Guest
Posts: n/a
 
      11-26-2009
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
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      11-26-2009
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)

 
Reply With Quote
 
 
 
 
Ramdas
Guest
Posts: n/a
 
      11-26-2009
On Nov 27, 1:33*am, MRAB <(E-Mail Removed)> 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 .....
 
Reply With Quote
 
Lie Ryan
Guest
Posts: n/a
 
      11-26-2009
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?
 
Reply With Quote
 
Ramdas
Guest
Posts: n/a
 
      11-27-2009
On Nov 27, 2:39*am, Lie Ryan <(E-Mail Removed)> 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
 
Reply With Quote
 
Lie Ryan
Guest
Posts: n/a
 
      11-29-2009
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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IPSEC: reserved not zero on payload message when connecting site-to-site Arjan Cisco 2 10-13-2005 06:37 PM
5350 can't use G711 payload type for fax pass-through?? Greg Cisco 2 04-05-2005 01:53 PM
Any problems with SIP phones not identifying payload sizes? CCGolfer VOIP 0 06-08-2004 08:44 PM
access HTTP payload in Java zhengyu Java 4 02-12-2004 07:15 PM
JMF: encrypting rtp payload junaid Java 0 12-30-2003 07:05 PM



Advertisments