阅读背景:

自v 1.7.1起,GAE / P:mail_stub.get_sent_messages失败,非ascii

来源:互联网 

My test code started failing with GAE version 1.7.1. I went back to 1.7.0 to wait for a fix but my test code is still failing with 1.7.2. Here is a minimal test that causes the failure:

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

mail.send_mail("[email protected]", "[email protected]", 
               u"sübject".encode("utf-8"), "body")
mail_list = self.mail_stub.get_sent_messages()

And I get the following error:

我收到以下错误:

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)

Could you let me know if I am doing something wrong or if this is a GAE bug?

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

1 个解决方案

#1


0  

After reading this post and this page, this seems to be the right way to do it:

阅读本文和本页后,这似乎是正确的方法:

from email import header
mail.send_mail("[email protected]", "[email protected]", 
               str(header.Header(u"sübject", "utf-8")), "body")

And it is working for me so far.

到目前为止它对我有用。


分享到: