OSError:[Errno 65]无主机路由。 Python 3.5.3

时间:2017-03-28 16:01:59

标签: python

我尝试通过SMTP连接到gmail,但是python没有连接到服务器:smtp.gmail.com。我不认为我的代码有问题,但现在是:

import smtplib
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)

smtpObj.ehlo()
smtpObj.starttls()

smtpObj.login('sending_Email@gmail.com', 'password')
smtpObj.sendmail('sending_Email@gmail.com', 'receiving_Email@gmail.com')
smptObj.quit()

我认为我必须启用一些设置,但没有任何工作。我正在使用运行OS X Yosemite 10.10.5的mac。感谢您的帮助。

这是我收到的错误消息。

Traceback (most recent call last):
File "/Users/jacobgreen/Documents/Comp Programming/Email Hack.py", line 3, in <module>
    smtpObj = smtplib.SMTP("smtp.gmail.com", 587)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 335, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 306, in _get_socket
    self.source_address)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 712, in create_connection
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 703, in create_connection
    sock.connect(sa)
OSError: [Errno 65] No route to host

1 个答案:

答案 0 :(得分:1)

如果发生这种情况,请尝试连接到其他wifi网络并尝试再次运行该代码。如果我找到一种方法来编辑计算机上的设置,则需要使代码正常工作。我会在这里发布