gmail login failure using python and imaplib

情到浓时终转凉″ 提交于 2019-11-27 04:37:18

If you want to avoid this error without compromising your account's security, use OAuth to authenticate. The protocol is documented here, and there is Python sample code that shows the use of XOAUTH2 with imaplib.

Independent of this, you should consider enabling two-step verification on your account to make it more secure. If you do, you can use an App Password to connect to IMAP, which might also avoid the above warning.

You can try to turn on this: https://www.google.com/settings/security/lesssecureapps This action solved the same problem for me.

With the new gmail´s update, some mail servr or apps get blocked due to the new gmails security settings. To solve this, I went to https://www.google.com/settings/security page and 'enabled' Access for less secure apps.

I was able to solve this by using a text-mode browser (elinks) to verify my login from the remote server. I had already struggled a while, so I had already tried enabling unsafe apps and various other incantations.

After logging in to gmail.com in elinks (using the html-only interface and having a security code sent to my phone) I could use imaplib to access the gmail account. Presumably one must do web-authentication from the same IP one tries to use Python/imaplib from.

It's probably Better™ to use the OAuth protocol, but this way I got my script running again without rewriting it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!