Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

python - SMTPAuthenticationError 5.7.14 Please log 5.7.14 in via your web browser

I have a script which sends periodically reports to a list of recipients. Everything worked fine until today 4 am, when I checked my inbox and the reports didn't come.

By debugging the code:

import smtplib
username="my.user.account@gmail.com"
password="my.correct.password"

server=smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls() 
server.ehlo()
server.login(username,password)

#if login worked, it should send a message, but it is not working, so I will suppress this part

server.quit()

I receive the following (old known) result:

(250, b'smtp.gmail.com at your service, [SERVERIP] SIZE 35882577 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING CHUNKING SMTPUTF8') (220, b'2.0.0 Ready to start TLS') (250, b'smtp.gmail.com at your service, [SERVERIP] SIZE 35882577 8BITMIME AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH ENHANCEDSTATUSCODES PIPELINING CHUNKING SMTPUTF8') Traceback (most recent call last): File "<pyshell#52>", line 6, in server.login(username,password) File "C:PythonPython36libsmtplib.py", line 729, in login raise last_exception File "C:PythonPython36libsmtplib.py", line 720, in login initial_response_ok=initial_response_ok) File "C:PythonPython36libsmtplib.py", line 641, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu5 5.7.14 wJL_YP3XLTGPzP_UBwtyCHhzHE1y1G8R0iHaz_pxG9fBH4CePmbXuAE1qH8HvnXTgqcmKi 5.7.14 P23_lJoZX_pfbNUOxQp4Fr2VhgbAjnlu3ZL_pcjVBd-TTMUVCAah6Q2-Vq5Dffm9s4UWwl 5.7.14 J7V7CjE06eHkw1IlphV4lLbRKVp9Hk7vC92zLQ5zM27cbQiTM8W3lEgm> Please log 5.7.14 in via your web browser and then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/answer/78754 r131sm2964505vkr.40 - gsmtp')

Things I've tried

Allow less secure apps (as indicated in https://www.google.com/settings/security/lesssecureapps): This flag was set to true since I created the account.

Disable Captcha (as indicated in https://accounts.google.com/DisplayUnlockCaptcha): Visited this URL several times. No luck.

Login via browser: It works fine, when logging via any Internet Browser from any computer, although in the first times I had to insert a code sent to the account's recovery phone.

I came across other things I could try, but I am not sure it could work:

  • Specific app passwords
  • Oauth2
  • Change or reset password

I will probably try oauth2, however it would require a change in my code, which I want to avoid due to some restrictions in the server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this issue as well. My mail forwarder script that has been working fine for 6+ months randomly started throwing this error:

534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbts 5.7.14 y2ku2-8KrWsn_dAUhnkssuTuESwaeG-DNn9hWBpsSpJCmVL ZhH24jzJfd-5bHUdh993dJ7 5.7.14 a5LsAOJrheyT0cRXIhMSbycqvMAC7sNrizO5qU_6iDescJcQa-QqUUCFVH7IZoWF9uXyrv 5.7.14 HC9XzAW-pBwgUjV4i_ts8CNhB_yZf2JHOi-wl6gZ9jwAiYLWx DPe7epI> Please log 5.7.14 in via your web browser and then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/answer/78754 y5sm3059043 9pge.49 - gsmtp

After some research I tried all the following steps:

  • Checking allow low secure apps in Google settings (it was already on, tried turing it off and back on)
  • Trying the unlock captcha link: https://accounts.google.com/DisplayUnlockCaptcha
  • Singing in and out of Google account manually (verifying with phone number)
  • Changing the account password
  • Enabling and disabling 2FA
  • Countless other things...

Nothing seemed to actually work at first. However, after doing all the above steps, the script started working again ~24 hours later without any modifications.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...