python GAE : incoming mail handler error

标签 python google-app-engine email handler

我正在 GAE 上编写可以解析和存储传入邮件的应用程序。我已经为电子邮件解析准备了一些简单的代码,但是当我尝试模拟从本地开发服务器上的管理开发控制台接收电子邮件时,出现了问题:

/develop/google_appengine/google/appengine/runtime/wsgi.py", line 193, in Handle
    result = handler(self._environ, self._StartResponse)
TypeError: 'module' object is not callable
INFO     2012-05-08 16:14:43,516 dev_appserver.py:2891] "POST /_ah/mail/test@example.com HTTP/1.1" 500 -

应用程序.yaml:

application: mailhandler
version: 1
runtime: python27
api_version: 1
threadsafe: true

inbound_services:
- mail

handlers:
- url: /_ah/mail/.+ 
  script: email_handler
  login: admin

email_handler.py:

from google.appengine.ext import webapp 
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler 
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail

from models import DataStoreManager

class LogSenderHandler(InboundMailHandler):
    # Receiving new mail message and parsing it
    def receive(self, mail_message):                                                                                                                      
        manager = DataStoreManager()
        instance = manager.get_instance_by_email(mail_message.sender.lowercase())

        email_key = manager.store_email(instance, instance.user, mail_message, mail_message.attachments)

我做错了什么?

最佳答案

我认为发生的情况是,在您的 app.yaml 中,您将模块/文件定义为脚本而不是应用程序,该模块当然不可调用。

app.yaml 定义更改为:

handlers:
- url: /_ah/mail/.+ 
  script: email_handler.application
  login: admin

并在 email_handler.py 的末尾添加这一行

application = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)

这里是文档: https://developers.google.com/appengine/docs/python/mail/receivingmail

关于 python GAE : incoming mail handler error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10537659/

相关文章:

php - 谷歌云 : Unable to establish MySql DB connection from PHP

java - 不支持登录方式! JavaMail、Dovecot、CentOS 7

python - 在索引列表上使用列表方法

Python加速重建列表的代码

python - 是否有一个工具包可以为远程 IMAP 服务器提供基于 Web 的 API(xmlrpc、REST 等)?

html - 发送 html/图像电子邮件的最佳方式是什么?

windows - 在 Laravel 5 中发送电子邮件不起作用

python - Celery 中的异常处理?

python奇怪的 super 声明: multiple self

python - App Engine - 在运行时指定实体名称