Привет, я пытаюсь понять, почему я получаю эту ошибку. Это меня немного озадачило. Я использую Python 3.6
logger = logging.getLogger(__name__)
message_text = 'this is a test body'
message = MIMEText(message_text)
message['to'] = 'me@example.com'
message['from'] = 'you@example.com'
message['subject'] = 'test subject'
logger.debug('++++++++++++++++++++++++++++++++++')
logger.debug(message)
logger.debug('++++++++++++++++++++++++++++++++++')
try:
raw = base64.urlsafe_b64encode(message.encode('UTF-8')).decode('ascii')
except Exception as e:
logger.debug('---------------')
logger.debug(e)
logger.debug('---------------')
И это вывод.
++++++++++++++++++++++++++++++++++
Content-Type: text/plain; charset="us-ascii".
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit.
to: me@example.com
from: you@example.com
subject: test subject
this is a test body
++++++++++++++++++++++++++++++++++
---------------
'MIMEText' object has no attribute 'encode'
---------------