Home > Blockchain >  Invalid credentials (Failure) Gmail from Python without Less secure apps
Invalid credentials (Failure) Gmail from Python without Less secure apps

Time:06-03

Google just disable the option to acces GMAIL disableing the option of work with Less secure Apps: https://support.google.com/accounts/answer/6010255?authuser=3&hl=es-419&authuser=3&visit_id=637897778656476957-2028222503&p=less-secure-apps&rd=1

[ERROR] error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 65, in lambda_handler
    imap4Obj = conectar_imap_correo(config_diccionario)
  File "/var/task/cargar_mensajes.py", line 31, in conectar_imap_correo
    imap4Obj.login(config_diccionario['credenciales']['default_email'],config_diccionario['credenciales']['password'])
  File "/var/lang/lib/python3.7/imaplib.py", line 598, in login
    raise self.error(dat[-1])

Any idea to fix this issue?

CodePudding user response:

The deprecation of "less secure apps" means that apps that request username/password credentials will no longer work. Instead you have to use OAuth2 to authenticate. You will have to learn how to implement it and apply the changes to your application's sign-in flow.

Aside from this there is no other workaround. This is just an evolution in security standards that Google has been announcing for a while. In their documentation they say that Google Workspace accounts will keep LSAs for a while longer, but this is probably to allow more time for large enterprise companies to migrate away from legacy apps. Your only real long-term solution is to start using OAuth. I suggest you get started with Google's Python API docs and samples.

  • Related