Forums

OSError: [Errno 101] Network is unreachable

Hi,

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/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/app.py", line 1951, in 
full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/app.py", line 1820, in 
handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/app.py", line 1949, in 
full_dispatch_request
rv = self.dispatch_request()
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask/app.py", line 1935, in 
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./flaskmovie/routes.py", line 41, in register
user.confirmation_email()
File "./flaskmovie/models.py", line 89, in confirmation_email
mail.send(message)
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask_mail.py", line 491, in send
with self.connect() as connection:
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask_mail.py", line 144, in __enter__
self.host = self.configure_host()
File "/home/teetwofour/.virtualenvs/env/lib/python3.7/site-packages/flask_mail.py", line 158, in configure_host
host = smtplib.SMTP(self.mail.server, self.mail.port)
File "/usr/lib/python3.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.7/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.7/smtplib.py", line 307, in _get_socket
self.source_address)
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable

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

Thank you.

-teetwofour

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'] = 'smtp.googlemail.com'
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.

Thanks!

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.