在 python 脚本中,我有以下内容:
with smtplib.SMTP_SSL(sender_server, 465, context=context) as server:
server.login(sender_email, sender_password)
server.sendmail(
sender_email, email, message.as_string()
)
在我编写脚本的 Windows 机器上,一切都按预期进行,电子邮件的发送和交付没有问题。但是,当我尝试在 Linux VPS 上运行相同的代码时,每次都会抛出 TimeoutError。
Traceback (most recent call last):
File "script.py", line 151, in <module>
with smtplib.SMTP_SSL(sender_server, 465, context=context) as server:
File "/usr/lib/python3.6/smtplib.py", line 1031, in __init__
source_address)
File "/usr/lib/python3.6/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.6/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.6/smtplib.py", line 1037, in _get_socket
self.source_address)
File "/usr/lib/python3.6/socket.py", line 724, in create_connection
raise err
File "/usr/lib/python3.6/socket.py", line 713, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
什么可能导致这种差异?我的谷歌搜索并没有产生多少成果,但也许我只是在搜索错误的术语。
TimeoutError: [Errno 110] 连接超时
这意味着对远程系统的访问可能在通往系统的途中被阻止。鉴于您在“Linux VPS”上遇到此问题,连接可能被托管此 VPS 的公司阻止,或者您需要专门配置您的机器以允许此类访问。请咨询您的特定托管商及其文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句