OSError: [Errno 101] Network is unreachable


I am having the getting the following error when trying to send a message through gmail with my app.

OSError: [Errno 101] Network is unreachable

I am not too sure what the error is about, I did have a look on the forums and apparently free users might not be able to send emails due to problems with spamming in the past.

Is there anyway I can get my emails to be allowed through or is the only option to pay for any account.

I am beginner when it comes to this sort of thing but I imagine it is trying to send out my confirmation email to the user upon signing up but for some reasons this is failing.

Here is the full error trace:

2020-05-19 17:51:07,130: Exception on /register [POST]
Traceback (most recent call last):
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/", line 1951, in 
rv = self.handle_user_exception(e)
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/", line 1820, in 
reraise(exc_type, exc_value, tb)
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/", line 39, in reraise
raise value
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/", line 1949, in 
rv = self.dispatch_request()
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/", line 1935, in 
return self.view_functions[rule.endpoint](**req.view_args)
File "./flaskmovie/", line 41, in register
File "./flaskmovie/", line 89, in confirmation_email
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/", line 491, in send
with self.connect() as connection:
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/", line 144, in __enter__ = self.configure_host()
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/", line 158, in configure_host
host = smtplib.SMTP(self.mail.server, self.mail.port)
File "/usr/lib/python3.7/", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.7/", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.7/", line 307, in _get_socket
File "/usr/lib/python3.7/", line 727, in create_connection
raise err
File "/usr/lib/python3.7/", line 716, in create_connection
OSError: [Errno 101] Network is unreachable

Can someone please help me find a way to solve this!

Thank you.


SMTP using GMail should work -- we have an exception for their servers, as we figure that they are very much capable of handling any anti-spam measures. What specific email server is your code configured to use?

Hi I am using this flask_mail along with:

app.config['MAIL_SERVER'] = ''
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True

what is interesting is that I tested this morning and it seemed to work fine?!?!?

No idea why but it does seem to be working now, hopefully it continues this way otherwise I may end up looking into one of the services such as sendgrid recommended here.


It looks like Google have changed the IPs involved and the way that we were using to find the IPs before does not seem to work any more. We are trying to work out what the new way is to get the appropriate IPs and provide the exceptions that are necessary to make it work.

Ok. We've added the new IP range to the rules so it should work now.