Forums

OSError: [Errno 101] Network is unreachable when connecting to smtp.gmail.com on port 587

Currently doing:

context = ssl.create_default_context()
with smtplib.SMTP("smtp.gmail.com", 587, timeout=20) as smtp:
    smtp.ehlo()
    smtp.starttls(context=context)
    smtp.ehlo()
    smtp.login(sender_login, config.password) 
    smtp.send_message(em)

I get:

File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__ (code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.10/smtplib.py", line 341, in connect self.sock = self._get_socket(host, port, self.timeout) 
File "/usr/local/lib/python3.10/smtplib.py", line 312, in _get_socket return socket.create_connection((host, port), timeout, 
File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection raise err 
File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection sock.connect(sa)
OSError: [Errno 101] Network is unreachable

it’s a scheduled task.

Im on a free plan.

What is a good suggestion to fix it? Should I use a HTTPS email API instead?

We are also facing this same issue suddenly. I was working till yesterday.

Looks like maybe something changed on gmail side. We will look into that.

Is there any update regarding this issue?