来自 Python 的无效凭据(失败)Gmail 没有安全性较低的应用程序

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

Google 仅禁用访问 GMAIL 的选项禁用使用安全性较低的应用程序的选项: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])

有解决此问题的想法吗?

弃用“不太安全的应用程序”意味着请求 username/password 凭据的应用程序将不再有效。相反,您必须使用 OAuth2 进行身份验证。您将必须学习如何实施它并将更改应用于应用程序的 sign-in 流程。

除此之外没有其他解决方法。这只是 Google 为 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 宣布的安全标准的演变。