[Tutor] Error Using A List And SMTP

Walter Prins wprins at gmail.com
Wed May 16 13:19:20 CEST 2012

Hi Sarma

On 16 May 2012 11:13, Sarma Tangirala <tvssarma.omega9 at gmail.com> wrote:

> Hey guys,
> I was just trying out SMTP and I keep getting a attribute error, *AttributeError:
> 'list' object has no attribute 'lstrip''*, when I use a list to store the
> send address.
> Code - http://pastebin.com/9NmCNdRb
> Traceback - http://pastebin.com/m1cgKDnn
> I'm not sure I understand why this is happening.

All the headers in the MimeText object needs to be strings.  You can't
directly pass a list object containing multiple recipients to the "To"
header of your MimeText object on line 31 in your code, and expect it to
work.  You've got to instead first convert the list to valid string and
assign that instead, as that's what the MimeText object expects.  You can
infer this from your error messages since lstrip() is a string method, and
the code is (rightly) complaining that a list doesn't have an lstrip()
method, which is understandable becuase you're getting the error when you
pass a list as parameter.

A quick google yields this question/answer on stackoverflow which is
relevant to your question. (See the "cc:" bits):

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120516/f426b944/attachment.html>

More information about the Tutor mailing list