Jacob Green
Jacob Green

Reputation: 61

OSError: [Errno 65] No route to host. Python 3.5.3

I'm trying to connect to gmail through SMTP, but python is not connecting to the server: smtp.gmail.com. I don't think there is something wrong with my code, but here it is:

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

smtpObj.ehlo()
smtpObj.starttls()

smtpObj.login('[email protected]', 'password')
smtpObj.sendmail('[email protected]', '[email protected]')
smptObj.quit()

I think there is some settings I have to enable, but nothing is working. I am using a mac running OS X Yosemite 10.10.5. Thanks for your help in advance.

This is the error message I am getting.

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

Upvotes: 3

Views: 9525

Answers (1)

Jacob Green
Jacob Green

Reputation: 61

If this is happening to you, try connecting to a different wifi network and attempt to run the code again. If I find a way to edit the setting on your computer needed to make the code work. I'll post it here

Upvotes: 2

Related Questions