Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Python email exception

Posted on 2009-05-05
4
Medium Priority
?
344 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses

636 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