23

I am running a cron job which executes the python script for reading gmail (2 min interval). I have used imaplib for reading the new mails. This was working fine until yesterday. Suddenly its throwing below error

imaplib.error: [AUTHENTICATIONFAILED] Invalid credentials (Failure)

and sometimes i am getting the below error

raise self.abort(bye[-1]) imaplib.abort: [UNAVAILABLE] Temporary System Error

When i run the same script on a different machine. Its working fine. I am assuming that the host has been blacklisted or something like that.

What are my options ?

I cant generate the Credentials (Gmail API) as this is under company domain account.

Mourya Ch
  • 243
  • 1
  • 2
  • 8
  • Gmail has set some internal limitations like downloading. Check that limit. https://support.google.com/a/answer/1071518?hl=en Gmail will not showing appropriate error. Another machine IP address is different so that same code is working on his machine. – Ravindra Sinare Oct 14 '15 at 07:57
  • bandwidth cannot be exceeding the allowed limit. as there are only 3-4 mails from yesterday. – Mourya Ch Oct 14 '15 at 08:15
  • Take call from google support, may your IP is blocked. It happened with me some months ago. – Ravindra Sinare Oct 14 '15 at 09:46
  • Do you have scope https://mail.google.com/. If your account is locked, you can unlock it using this link https://om4.com.au/google-apps-gmail-invalid-credentials-unlock-captcha/ – SGC Oct 14 '15 at 23:51
  • Focus on working out why your credentials are invalid... the system error is possibly not your fault, but the credentials certainly are. – John Mee Oct 19 '15 at 06:40
  • 2
    Thanks guys. Its working now. The issue was that the google blocked our network.. because of multiple attempts. I tried that unlock URL from a different URL and it didnt work. The catch is that, we have to run that URL in the machine where you are trying to run the script. Hope it may help someone :) – Mourya Ch Nov 03 '15 at 06:27

8 Answers8

37

try with:

1) https://myaccount.google.com/lesssecureapps?pli=1

2) Gmail Settings -> Forwarding and POP / IMAP -> IMAP Acess to Enable IMAP

  • Hi, welcome to Stack Overflow. Please provide context for links. Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. https://stackoverflow.com/help/how-to-answer – ArielGro Jan 26 '20 at 21:45
  • Thank you! None of these answers helped but this one. Wish it was marked as the right answer. – Nv7 Mar 04 '20 at 00:37
  • this answer should be the accepted one since it is probably the most prevalent cause for the issue. – Zenahr Jun 29 '21 at 10:53
  • 1
    As like @Nv7, the above answers does not work for me too. – miltonbhowmick Jul 27 '22 at 08:14
  • this didn't work for me – Lokesh thakur Jan 18 '23 at 05:28
  • Google Account setting "Less secure app access" does no longer work (February 2023). Using the link above shows the message "This setting is no longer available". – zrajm Feb 19 '23 at 23:50
26

Some apps and devices use less secure sign-in technology. So we need to enable Less secure app access option from gmail account.

Steps:

  1. Login into Gmail
  2. Go to Google Account
  3. Navigate to Security section
  4. Turn on access for Less secure app access

By following above steps, issue will be resolved.

mnille
  • 1,328
  • 4
  • 16
  • 20
Sagar Bhavsar
  • 278
  • 3
  • 8
3
Ensure you have entered the right password

Even after that if it is not working
  • Enable the IMAP Access at: Gmail Settings> Forwarding and POP / IMAP> IMAP Acess

  • Enable 2-factor authentication for the google account

  • then generate an app-specific password (https://myaccount.google.com/apppasswords)

  • Use this newly generated password for imap login

Harshal Deore
  • 1,050
  • 1
  • 11
  • 11
2

Got the same error and it was fixed by getting the new google app password. Maybe this will work for someone

applekate
  • 304
  • 3
  • 8
2

This can be solved in two steps:

MiraTech
  • 1,108
  • 18
  • 35
1

Thanks guys. Its working now. The issue was that the google blocked our network.. because of multiple attempts. I tried that unlock URL from a different URL and it didnt work. The catch is that, we have to run that URL in the machine where you are trying to run the script. Hope it may help someone :)

Mourya Ch
  • 243
  • 1
  • 2
  • 8
0

Google Gmail - Security - Less secure app access ... won't work anymore !

See https://support.google.com/accounts/answer/6010255?hl=en

“To help keep your account secure, from May 30, 2022, ​​Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.”

Regards Diego

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 27 '22 at 15:57
0

Now Google has created set of libraries to read Gmail data, after creating project in API and Services on Google Cloud. Following link contains python quickstart guide for same: https://developers.google.com/gmail/api/quickstart/python

After following the steps, when I got a link from my script to proceed through Browser after logging I was getting "Access Blocked: project has not completed the Google Verification process". Then I found this Youtube video, which solved this issue as well.

Shams
  • 3,637
  • 5
  • 31
  • 49