Forums

No login to Gmail

When I run the code

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(mail, secret)

in my python3.6 console I get this error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.6/smtplib.py", line 730, in login raise last_exception File "/usr/lib/python3.6/smtplib.py", line 721, in login initial_response_ok=initial_response_ok) File "/usr/lib/python3.6/smtplib.py", line 642, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu\n5.7.14 AJRKZXL9Mj64ceQgegOeYr1kyAmmgyfL8lMftqnannGWpvjP bfhcAcDyoYFNzAXdxKvaQ\n5.7.14 TgOytteaKK7Mx4sxE0tZWNW2OGHR90yz9iM7tJkJojy9f8NaKE8cIUWr66YydFMf>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 y18sm9533706qki.0 - gsmtp').

When I run the code on my local computer it works fine. I also logged in via my web browser as suggested with no result. What is the issue here?

That's caused by Google seeing connections from cloud computing environments as being more likely to be coming from hackers than it does connections from your home/work network. The best way around it is to use an app-specific password -- the section at the bottom of this help page has some details.

Thank you, I fixed it.