?
Solved

Python email exception

Posted on 2009-05-05
4
Medium Priority
?
341 Views
Last Modified: 2012-05-06
Hi experts,

I try to use the attached code to retrieve e-mails, however I got

david@xadapp3:~/test$ sudo python EmailContent.py
Traceback (most recent call last):
  File "EmailContent.py", line 52, in <module>
    email.mailstats('geek')
  File "EmailContent.py", line 26, in mailstats
    str  = self.msgfactory(fp)
  File "EmailContent.py", line 14, in msgfactory
    except email.errors.MessageParseError:
AttributeError: EmailContent instance has no attribute 'errors'


I have imported "email", "mailbox", etc.

Anybody knows why I got an error?

Thanks so much.

def msgfactory(self, fp):
        try:
            return email.message_from_file(fp)
        except email.errors.MessageParseError:
        # Don't return None since that will
        # stop the mailbox iterator
            return ''
 
    def mailstats(self, user):
        if os.path.isfile('/var/spool/mail/'+user):
            fp=open('/var/spool/mail/'+user)
        else:
            print 'I cannot open mail for user',user
            sys.exit(1)
 
        str  = self.msgfactory(fp)
        mbox = mailbox.UnixMailbox(fp, str)
 
      ..................

Open in new window

0
Comment
Question by:davidw88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Expert Comment

by:LunarNRG
ID: 24309592
Add 'import email.errors' near where you imported 'email' and 'mailbox'.
0
 
LVL 8

Expert Comment

by:LunarNRG
ID: 24309604
Have you defined a variable named 'email' anywhere in your code? Something like this ...

import email
import email.errors
import mailbox


email = email.Message(...)

...
0
 
LVL 8

Accepted Solution

by:
LunarNRG earned 500 total points
ID: 24309644
If so, you should avoid rebinding names of imported modules. Otherwise, how can you refer to the module named 'email', after you assign an object to the name 'email' (ie. email = 'something else but not the module').
0
 

Author Comment

by:davidw88
ID: 24309847
thanks LunarNRG!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question