【问题标题】:Connecting to SMTP server failing on Linux but not Windows在 Linux 而不是 Windows 上连接到 SMTP 服务器失败
【发布时间】:2020-06-28 04:46:28
【问题描述】:

在 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

什么可能导致这种差异?我的 Google 搜索结果不大,但也许我只是在搜索错误的字词。

【问题讨论】:

    标签: python ssl smtp


    【解决方案1】:

    TimeoutError: [Errno 110] 连接超时

    这意味着对远程系统的访问可能在通往系统的途中被阻止。鉴于您在“Linux VPS”上遇到此问题,很可能是托管此 VPS 的公司阻止了连接,或者您需要专门配置您的机器以允许此类访问。请咨询您的特定托管商及其文档。

    【讨论】:

      猜你喜欢
      • 2016-06-12
      • 1970-01-01
      • 2015-09-25
      • 2020-03-20
      • 2019-07-23
      • 2020-10-22
      • 1970-01-01
      • 2016-11-12
      • 2022-08-16
      相关资源
      最近更新 更多