How to receive inbound messages with unicode subject?

孤人 提交于 2019-12-11 10:52:36

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/16019811/how-to-receive-inbound-messages-with-unicode-subject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!