b = unicode(a, "utf-8")

[snip]

msg = MIMEText(b)

I believe this is the problem line -- the MIMEText constructor takes encoded strings rather than unicode objects. Try:

msg = MIMEText(a)

Or, alternatively

msg = MIMEText(b.encode('utf-8'))

On Fri, 11 Sep 2009 16:33:42 -0700, rh0dium <steven.kl...@gmail.com> wrote:

Hi Geniuses,

Can anyone please show me the way..  I don't understand why this
doesn't work...


# encoding: utf-8
from email.MIMEText import MIMEText

msg = MIMEText("hi")
msg.set_charset('utf-8')
print msg.as_string()

a = 'Ho\xcc\x82tel Ste\xcc\x81phane '
b = unicode(a, "utf-8")

print b

msg = MIMEText(b)
msg.set_charset('utf-8')
print msg.as_string()

It should right??

Thanks!



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to