Google App Engine python入站邮件LookupError:未知编码 [英] Google App Engine python inbound mail LookupError: unknown encoding

查看:350
本文介绍了Google App Engine python入站邮件LookupError:未知编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用标准入站邮件处理程序收到我的Google App Engine应用程序的入站电子邮件,其中包含以下示例在文档



看起来,某个电子邮件发送到应用程序(而不是我)正在导致电子邮件api引发LookupError:未知的编码异常。请参阅回溯。



据我所知,在应用程序的邮件处理程序被调用之前抛出此异常,显然使得应用程序的代码无法捕获和处理。这是真的吗?



似乎App Engine每隔大约40分钟重试一次失败的消息,这会继续产生错误(并且警报...)有什么方法可以放弃这个?



感谢您的帮助。

追踪:

追踪(最近一次调用最后):
文件/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2 .py,第1535行,在__call__
rv = self.handle_exception(request,response,e)
文件/ base / data / home / runtimes / python27 / python27_lib / versions / third_party / webapp2- 2.5.2 / webapp2.py,第1529行,在__call__
rv = self.router.dispatch(request,response)
文件/ base / data / home / runtimes / python27 / python27_lib / versions / base / data / home / runtimes / python27 / python27_lib /版本/ THIRD_PARTY /webapp2-2.5.2/webapp2.py,第1102行,在__call__
return handler.dispatch()
文件/ base / data / home / runtimes / python27 / python27_lib / versions / third_party / webapp2-2.5.2 / webapp2.py,第572行,发送
返回self.handle_exception(e,self.app.debug)
文件/ base / data / home / runtimes / python27 / python27_lib / versions / third_party / webapp2-2.5.2 / webapp2.py,第570行,发送
返回方法(* args,** kwargs)
文件/ base / data / home / runtimes /python27/python27_lib/versions/1/google/appengine/ext/webapp/mail_handlers.py,第70行,在
self.receive(mail.InboundEmailMessage(self.request.body))
文件/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py,第939行,在__init__
self.update_from_mime_message(mime_message)
文件/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py,第1513行,在update_from_mime_message
super(InboundEmailMessage,s elf).update_from_mime_message(mime_message)
文件/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py,第1422行,update_from_mime_message
super(EmailMessage,self).update_from_mime_message(mime_message)
在update_from_mime_message中的文件/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py,第1291行
subject = _decode_and_join_header(mime_message ['subject'],separator = u'')
文件/ base / data / home / runtimes / python27 / python27_lib / versions / 1 / google / appengine / api / mail.py,第597行,在_decode_and_join_header中,
代表s,charset在email.header.decode_header(header))
文件/ base / data / home / runtimes / python27 / python27_lib / versions / 1 /google/appengine/api/mail.py,第597行,在
中为s,在email.header.decode_header(header)中为charset)
LookupError:unknown encoding:iso-8859-8-i


解决方案

错误正在发生w hen入站邮件处理程序的 post 方法被调用。

 文件/ (自我.request。)中的base / data / home / runtimes / python27 / python27_lib / versions / 1 / google / appengine / ext / webapp / mail_handlers.py,第70行。 body))

最简单的解决方案是覆盖 post

 从google.appengine.ext导入日志记录
。 webapp.mail_handlers import InboundMailHandler

$ b class MyInboundMailHandler(InboundMailHandler):

def post(self):
try:
super(MyInboundMailHandler ,self).post()
除LookupError之外如下:
logging.warning('Could not process message because%s。',ex)

def receive(self, mail_message):
#进程信息

如果你不想丢失信息, ÿ您可以创建并注册一个自定义 iso-8859-8-i 编解码器。这似乎不是一个有据可查的流程,但这些问题提供了一些提示:

我该如何正确创建自定义文本编解码器?



自定义Python Charmap Codec



我该如何写在python中的自定义编码来清理我的数据?



标准库的 iso-8859-8编码提供了一个很好的模板。


I am receiving inbound email to my Google App Engine app, using a "standard" inbound mail handler, following the examples in the docs.

It seems that a certain email message sent to the app (not by me) is causing the email api to throw a LookupError: unknown encoding exception. Please see the traceback.

As far as I can tell this exception is thrown before the app's mail handler is invoked, apparently making it impossible to catch and handle by the app's code. Is this really the case ?

It also seems that App Engine retries the failed message at approximately 40 minutes intervals, which continues to produce errors (and alerts...) Is there any way to abort this ?

Thanks for your help.

Traceback:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/webapp/mail_handlers.py", line 70, in post
    self.receive(mail.InboundEmailMessage(self.request.body))
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 939, in __init__
    self.update_from_mime_message(mime_message)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 1513, in update_from_mime_message
    super(InboundEmailMessage, self).update_from_mime_message(mime_message)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 1422, in update_from_mime_message
    super(EmailMessage, self).update_from_mime_message(mime_message)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 1291, in update_from_mime_message
    subject = _decode_and_join_header(mime_message['subject'], separator=u'')
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 597, in _decode_and_join_header
    for s, charset in email.header.decode_header(header))
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py", line 597, in 
    for s, charset in email.header.decode_header(header))
LookupError: unknown encoding: iso-8859-8-i

解决方案

The error is happening when the inbound mail handler's post method is called.

  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/webapp/mail_handlers.py", line 70, in post
    self.receive(mail.InboundEmailMessage(self.request.body))

The simplest solution is to override the post method in your own handler to trap the error:

import logging
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler


class MyInboundMailHandler(InboundMailHandler):

    def post(self):
        try:
            super(MyInboundMailHandler, self).post()
        except LookupError as ex:
            logging.warning('Could not process message because %s.', ex)

    def receive(self, mail_message):
        # Process message

If you don't want to lose the message, you could create and register a custom iso-8859-8-i codec. This doesn't seem to be a well-documented process, but these questions provide some hints:

How do I properly create custom text codecs?

Custom Python Charmap Codec

how do I write a custom encoding in python to clean up my data?

And the standard library's iso-8859-8 encoding provides a good template.

这篇关于Google App Engine python入站邮件LookupError:未知编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆