我有一个脚本,它定期向收件人列表发送报告.一切正常,直到今天凌晨 4 点,当我检查收件箱并没有收到报告时.
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.
通过调试代码:
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 为您服务,[SERVERIP] SIZE35882577 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING CHUNKING SMTPUTF8')(220, b'2.0.0 Ready to start TLS') (250, b'smtp.gmail.com at your服务,[SERVERIP] SIZE 35882577 8BITMIME AUTH LOGIN PLAIN XOAUTH2PLAIN-CLIENTTOKEN OAUTHBEARERXOAUTH ENHANCEDSTATUSCODES PIPELINING CHUNKING SMTPUTF8')Traceback(最近一次调用最后一次):文件<pyshell#52>",第 6 行,在server.login(username,password) 文件C:PythonPython36libsmtplib.py",第 729 行,登录在登录中引发 last_exception 文件C:PythonPython36libsmtplib.py",第 720 行initial_response_ok=initial_response_ok) 文件C:PythonPython36libsmtplib.py",第 641 行,在 auth引发 SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, b'5.7.14<https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu5 5.7.14wJL_YP3XLTGPzP_UBwtyCHhzHE1y1G8R0iHaz_pxG9fBH4CePmbXuAE1qH8HvnXTgqcmKi 5.7.14P23_lJoZX_pfbNUOxQp4Fr2VhgbAjnlu3ZL_pcjVBd-TTMUVCAah6Q2-Vq5Dffm9s4UWwl 5.7.14J7V7CjE06eHkw1IlphV4lLbRKVp9Hk7vC92zLQ5zM27cbQiTM8W3lEgm>请通过网络浏览器登录 5.7.14,然后重试. 5.7.14 了解更多信息请参见 5.7.14 https://support.google.com/mail/answer/78754一个>r131sm2964505vkr.40 - gsmtp')
(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')
我尝试过的事情
允许安全性较低的应用程序(如 https://www.google.com/settings/security/lesssecureapps):自从我创建帐户以来,此标志已设置为 true.
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.
禁用验证码(如 https://accounts.google.com/DisplayUnlockCaptcha 中所示):多次访问此 URL.没有运气.
Disable Captcha (as indicated in https://accounts.google.com/DisplayUnlockCaptcha): Visited this URL several times. No luck.
通过浏览器登录:在任何计算机上通过任何 Internet 浏览器登录时,它都可以正常工作,尽管在第一次我必须插入发送到帐户的辅助电话的代码.
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:
我可能会尝试 oauth2,但它需要更改我的代码,由于服务器中的一些限制,我想避免这种情况.
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.
我已经使用 Google Gmail API 解决了这个问题.谷歌似乎已经阻止或限制了通过未知设备登录我的帐户,因为我只能通过浏览器登录,并且在我确认了电话号码和短信发送的代码之后.
I have solved this using the Google Gmail API. It seems Google has either blocked or limited logins for my account through unknown devices, as I could login only via the browser and after I confirmed the telephone number and an code sent by SMS.
所以我决定放弃使用 smtplib 并使用 Google 用于 Gmail 的 API 实现访问:https://developers.google.com/api-client-library/python/一个>https://developers.google.com/gmail/api/guides/sending
So I decided to give up using smtplib and implemented the access using the API Google uses for Gmail: https://developers.google.com/api-client-library/python/ https://developers.google.com/gmail/api/guides/sending
希望这对遇到此问题的其他人有所帮助.
Hope this helps other who had trouble with this issue.
这篇关于SMTPAuthenticationError 5.7.14 请通过网络浏览器登录 5.7.14的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!