FAQ
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!

Search Discussions

  • MRAB at Sep 12, 2009 at 12:01 am

    rh0dium 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??
    'b' is Unicode, but you're telling 'msg' that it's UTF-8, which it
    isn't. Try giving 'msg' the UTF-8 string:
    msg = MIMEText(a)
    msg.set_charset('utf-8')
    print msg.as_string()
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/plain; charset="utf-8"

    Ho?tel Ste?phane
  • Rami Chowdhury at Sep 12, 2009 at 12:01 am

    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 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)
  • Bouncyinc at Sep 12, 2009 at 2:09 am
    How do you suppose it should work....and how is it working? what about the outpout difference?

    ----------
    Sent via Cricket Mobile Email

    ------Original Message------
    From: rh0dium <steven.klass at gmail.com>
    To: <python-list at python.org>
    Date: Fri, 11 Sep 2009 04:33:42 PM -0700
    Subject: Unicode - and MIMEType - Good friday fun.

    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!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 11, '09 at 11:33p
activeSep 12, '09 at 2:09a
posts4
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase