I'm trying to conncet to my gmail to download mails attachments. I wrote the following code:
import imaplib
email_user = 'my_email@gmail.com'
email_pass = 'my_pass'
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993)
mail.login(email_user, email_pass)
It throws and error:
error Traceback (most recent call last)
<ipython-input-8-945b3b5696e0> in <module>
----> 1 mail.login(email_user, email_pass)
c:\users\mikee\anaconda3\envs\gmail_attach\lib\imaplib.py in login(self, user, password)
610 typ, dat = self._simple_command('LOGIN', user, self._quote(password))
611 if typ != 'OK':
--> 612 raise self.error(dat[-1])
613 self.state = 'AUTH'
614 return typ, dat
error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
I enabled less secure apps and IMAP in gmail settings, I also checked that my account is not blocked and unlocked CAPTCHA by this link: https://accounts.google.com/DisplayUnlockCaptcha
Any ideas what could be the issue?