Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:46:16+00:00 2026-05-31T18:46:16+00:00

I am using the external library IMAPClient. When the login fails, i see this

  • 0

I am using the external library IMAPClient. When the login fails, i see this error : imaplib.error: [AUTHENTICATIONFAILED] Authentication failed.

When i try except imaplib.error: i get : AttributeError: 'module' object has no attribute 'error'

The documentation of imaplib says that the exception should be IMAP4.error
Then why is IMAPClient raising imaplib.error and how do i catch it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:46:17+00:00Added an answer on May 31, 2026 at 6:46 pm

    The error message you see:

    imaplib.error: [AUTHENTICATIONFAILED] Authentication failed.
    

    is describing the error as best it knows how; at the time the exception occurs, the exception class is called “imaplib.error”, because whoever is raising it has described it that way (more on this later). I poked around, and I think I’ve found it for you:

    Python 2.7.2 (default, Nov 14 2011, 19:37:59) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import imaplib
    >>> imaplib.IMAP4.error
    <class 'imaplib.error'>
    

    I opened up the imaplib.py file, and found what seems like an odd exception-throwing mechanism. “IMAP4” is a class, and “error” is a class defined inside the IMAP4 class. Python doesn’t appear to “nest” the classes – just the class definitions. So once an object of class “error” exists, it’s an object of class “error” which was defined in the scope “imaplib”. The fact that the “error” class definition was inside the “IMAP4” class lib definition is irrelevant to Python. On the other hand, in order for you to describe an object of class “error” before such an object exists, you need to reference it as imaplib.IMAP4.error in order for Python to find the definition of the class you are talking about.

    Very confusing, I know, and I didn’t really know all of this before I started investigating the question. Here’s a brief illustration:

    Python 2.7.2 (default, Nov 14 2011, 19:37:59) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class foo(object):
    ...   class bar(object):
    ...     pass
    ...   def b(self):
    ...     return bar()
    ... 
    >>> bar
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'bar' is not defined
    >>> foo.bar
    <class '__main__.bar'>
    >>> foo().bar()
    <__main__.bar object at 0x10048dd10>
    

    Basically, you were trying to do a very reasonable thing, but the way the imaplib library handles exception throwing is a little odd, making your life difficult. Long story short, you should try to catch imaplib.IMAP4.error and move on with your life.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using an external library function that returns a File object. This
I have a compiled external library that I'm using in my (Objective-C++) code. This
In my application I'm using an external library (Batik 1.7) that is made up
I have a problem; I'm using an external library where one particular event has
Is there any external library using which one can edit and save XML files
I am using an external library for Artificial Neural Networks in my project.. While
I'm working on a project using many external library on windows. I got problem
Is there a way in C#, perhaps using an external library of some kind,
I'm using an external library written in Java ( Selenium ). One of the
I'm using an external library which returns an object array for the old state

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.