【问题标题】:TimeoutError: [Errno 60] Operation timed out (starttls())TimeoutError: [Errno 60] 操作超时 (starttls())
【发布时间】:2021-02-23 12:54:44
【问题描述】:

我之前遇到过一个问题,我收到了ValueError: server_hostname cannot be an empty string or start with a leading dot。在 Stack Overflow 中检查了this post,当我按照说明在控制台中运行时:

import smtplib

smtplib.SMTP_SSL(host='gmail-smtp-in.l.google.com').connect(host='gmail-smtp-in.l.google.com', port=25)

但是我得到了一个超时,如下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 1034, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 1040, in _get_socket
    new_socket = socket.create_connection((host, port), timeout,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)

在我的代码 server.starttls() 中启用时遇到问题。如果注释掉,它可以正常发送电子邮件。

下面是我的代码的 sn-p:

server = smtplib.SMTP_SSL()
server.connect('gmail-smtp-in.l.google.com', 25) # mail server  want to connect to.
server.set_debuglevel(True) # shows communication with the server in the console
server.ehlo()
server.starttls()
server.ehlo()

【问题讨论】:

  • 3.8也可能有这个bug,不如试试他们在其他帖子里说的吧?
  • 我尝试了另一篇文章中的建议,但它对我不起作用。仍然得到同样的错误
  • 您上面的代码没有显示。那么我们该如何提供帮助呢?发布minimal reproducible example
  • @Tomerikoo server = smtplib.SMTP_SSL(host = 'smtp.gmail.com').connect(host ='smtp.gmail.com',port = 465) # mail server we want to connect to. server.set_debuglevel(True) # shows communication with the server in the console server.ehlo() server.starttls() server.ehlo() 它挂起并且不发送电子邮件,而之前它抛出了一个错误 - 我也在控制台中尝试了 import smtplib;smtplib.SMTP_SSL(host='smtp.gmail.com').connect(host='smtp.gmail.com', port=465) 和相同的行为,它挂起

标签: python


【解决方案1】:

也许您可以尝试使用 python 3.9。我不知道您使用的是什么操作系统,但如果您使用的是 mac,则必须使用 pip3 而不是 pip,以便 python 可以理解它(mac 有 python 2 作为默认值)希望我能提供帮助:)

【讨论】:

  • 如果你有问题,你不会改变你正在使用的整个编程语言,你会尝试修复它。
  • 这会有什么不同?您是否有证据/来源证明该错误已在 3.9 中修复?
  • 不,这是一个想法,我没有证据,但我只是想提供帮助
猜你喜欢
  • 1970-01-01
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-18
相关资源
最近更新 更多