Encoding of headers in MIMEText

I found the solution. Email headers containing non ascii characters need to be encoded as per RFC 2047. In Python this means using email.header.Header instead of a regular string for header content (see http://docs.python.org/2/library/email.header.html). The right way to write the above example is then

from email.mime.text import MIMEText
from email.header import Header
body = "Some text"
subject = "» My Subject"                   
msg = MIMEText(body,'plain','utf-8')
msg['Subject'] = Header(subject,'utf-8')
text = msg.as_string()

The subject string will be encoded in the email as

=?utf-8?q?=C2=BB_My_Subject?=

The fact the in python 2.x the previous code was working for me is probably related to the mail client being able to interpret the wrongly encoded header.