Tuesday, January 26, 2010

App Engine: AttributeError: 'module' object has no attribute 'Message'

Today I wasted over an hour trying to receive mail in App Engine. Every time I'd try to use it, I'd get errors like:

'module' object has no attribute 'Message'
Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 509, in __call__
handler.post(*groups)
File "/base/python_lib/versions/1/google/appengine/ext/webapp/mail_handlers.py", line 58, in post
self.receive(mail.InboundEmailMessage(self.request.body))
File "/base/python_lib/versions/1/google/appengine/api/mail.py", line 546, in __init__
mime_message = _parse_mime_message(mime_message)
File "/base/python_lib/versions/1/google/appengine/api/mail.py", line 227, in _parse_mime_message
if isinstance(mime_message, email.Message.Message):
AttributeError: 'module' object has no attribute 'Message'

Turns out I'd named my file "email.py", which is a builtin module for python. Rename it and it works fine.

Don't forget to delete the email.pyc, or your dev_appserver will complain about "ImportError: No module named email.message".

5 comments:

Ganz said...

Thanks for posting this, I hit on pretty much the same problem by creating "time.py".

ghybujnon said...
This comment has been removed by the author.
Unknown said...

Yep me too - same problem - now fixed.

Anonymous said...

T.H.A.N.K. Y.O.U.

Chris W. said...

Wow. Thanks so much.

It's amazing how the stupidest/tiniest problems always waste the most time.