In my case the mistake was that I didn't properly login. so you must ensure you are doing so
M = imaplib.IMAP4_SSL('imap.gmail.com',993) M.login(you_email,your_password) M.select("Inbox")
I hope this will work.