Reputation: 11
I want to check gmail's mail.
I wrote this code with python.
import imaplib
import email
UserName = "my_gmail"
PassName = "my_gmail_password"
gmail = imaplib.IMAP4_SSL("imap.gmail.com", '993')
gmail.login(UserName, PassName)
gmail.select("")
head, data = gmail.search(None, 'ALL')
but occured this error.
error Traceback (most recent call last) in 8 9 gmail = imaplib.IMAP4_SSL("imap.gmail.com", '993') ---> 10 gmail.login(UserName, PassName) 11 gmail.select("") 12
~/.pyenv/versions/3.7.4/lib/python3.7/imaplib.py in login(self, user, password) 596 typ, dat = self._simple_command('LOGIN', user, self._quote(password)) 597 if typ != 'OK': --> 598 raise self.error(dat[-1]) 599 self.state = 'AUTH' 600 return typ, dat
error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
Why this error occure? And how do I slove this error? Please tell me.
Upvotes: 1
Views: 5624
Reputation: 321
Are you using 2-FA? if so, you have to set an application-specific password via gmail, and send that password instead of your regular password. Otherwise, this post might help.
It might cause a security hazard - but at least for the development stage you can go to your google account security settings and allow less secure apps (blocked by default).
Upvotes: 1