2012-05-10 12 views
2

私は、受信メールを解析して保存できるGAEのアプリケーションを作成しています。私は、電子メールの解析のためのいくつかの簡単なコードを用意しましたが、私は地元のdevのサーバー上で管理者のdevのコンソールからのメール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

問題は、あなたがいないですあなたのハンドラのためのWSGIApplicationを宣言してくださいLogSenderHandler

あなたが上でそのことについて読んでする必要があります、ドキュメントに書かれているとおり:あなたはyour app.yaml

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

に注意をWSGIアプリケーションを指定する必要が その後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) 

InboundMailHandlerには特別な方法がありますmappingはURLの地図を宣言するのに役立ちます。

関連する問題