When I receive message with Unicode subject, I am getting the following error:

'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 716, in __call__
    handler.post(*groups)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/mail_handlers.py", line 69, in post
    self.receive(mail.InboundEmailMessage(self.request.body))
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 742, in __init__
    self.update_from_mime_message(mime_message)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 1304, in update_from_mime_message
    super(InboundEmailMessage, self).update_from_mime_message(mime_message)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 1213, in update_from_mime_message
    super(EmailMessage, self).update_from_mime_message(mime_message)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 1093, in update_from_mime_message
    subject = _decode_and_join_header(mime_message['subject'], separator=u'')
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 558, in _decode_and_join_header
    for s, c in email.header.decode_header(header))
  File "/base/python_runtime/python_lib/versions/1/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 0xd0 in position 0: ordinal not in range(128)

The same problem happens with Development environment. Is there any way to fix it?

I see the following in e-mail headers:

Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
有帮助吗?

解决方案

I had to parse e-mail message manually since I haven't found a way to fix this problem - http://code.google.com/p/googleappengine/issues/detail?id=8989

Please see https://stackoverflow.com/a/16129023/604388 to understand how I do it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top