0

我的测试代码在 GAE 版本 1.7.1 中开始失败。我回到 1.7.0 等待修复,但我的测试代码在 1.7.2 中仍然失败。这是导致失败的最小测试:

mail.send_mail("sender@example.com", "receiver@example.com", 
               u"sübject".encode("utf-8"), "body")
mail_list = self.mail_stub.get_sent_messages()

我收到以下错误:

Traceback (most recent call last):
  File "/Users/.../tests/unit_tests.py", line 19, in testTest
    mail_list = self.mail_stub.get_sent_messages()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub.py", line 184, in WrappedMethod
    return method(self, *args, **kwargs)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py", line 183, in get_sent_messages
    email_message = mail.EmailMessage(mime_message=mime_message)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail.py", line 742, in __init__
    self.update_from_mime_message(mime_message)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail.py", line 1213, in update_from_mime_message
    super(EmailMessage, self).update_from_mime_message(mime_message)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail.py", line 1093, in update_from_mime_message
    subject = _decode_and_join_header(mime_message['subject'], separator=u'')
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail.py", line 558, in _decode_and_join_header
    for s, c in email.header.decode_header(header))
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail.py", line 558, in <genexpr>
    for s, c in email.header.decode_header(header))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)

如果我做错了什么或者这是 GAE 错误,你能告诉我吗?

4

1 回答 1

0

在阅读了这篇文章和这个页面之后,这似乎是正确的做法:

from email import header
mail.send_mail("sender@example.com", "receiver@example.com", 
               str(header.Header(u"sübject", "utf-8")), "body")

到目前为止,它对我有用。

于 2012-10-29T01:04:03.173 回答