2012-05-10 37 views
2

我在GAE上編寫應用程序,可以解析和存儲收到的郵件。我已經準備了電子郵件分析一些簡單的代碼,但不順心的事,當我嘗試模擬本地開發服務器上的管理,開發者控制檯電子郵件recieveing:Python 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/[email protected] HTTP/1.1" 500 - 

的app.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) 

我做錯了嗎?

+0

可以請你發佈整個回溯? – aschmid00

回答

7

我認爲會發生什麼情況是,在您的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

3

的問題是你不知道已經爲您的處理程序LogSenderHandler聲明瞭WSGIA應用程序。

您必須在閱讀有關: https://developers.google.com/appengine/docs/python/python27/using27

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) 

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

之後,你有your app.yaml

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

注指定WSGI應用:由於寫入文檔中,類InboundMailHandler有一個特殊的方法mapping可以幫助您聲明URL的映射。