Forums

OSERROR Errno 101 Network is unreachable

[formatted by admin]

File "/usr/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.8/smtplib.py", line 308, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/lib/python3.8/socket.py", line 807, in create_connection
    raise err
  File "/usr/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

Hi, check this help page https://help.pythonanywhere.com/pages/SMTPForFreeUsers/.

what url are you trying to reach when you get this error?

email_host = 'uit.telenet.be'

Hi, please check the help page I posted above.

help page is not helping me ! i am using the SMTP port 587

Free users are restricted to HTTP/HTTPS only, to a whitelist of sites. Because most email services work over SMTP, which is not HTTP or HTTPS, that means you cannot normally use SMTP on Free accounts.

If you want to send email, you have two options:

  • Use an HTTP/HTTPS-based email service (Services like Mailgun or sendgrid allow you to send email using HTTP(S) requests, and their API endpoint are on our whitelist. This is the most reliable option, and works well so long as your code isn't limited to using SMTP.)
  • Use Gmail's SMTP servers

If i use the Gmail's SMTP server then i get the Internal Server Error (500) raise SMTPAuthenticationError ! The email and password are correctly filled in and I had enabled access to less secure apps on my gmail account !

Can you show us full traceback error message and the relevant bits of your code?

When i use the Gmail server :

Traceback (most recent call last):
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/contrib/auth/views.py", line 222, in dispatch
    return super().dispatch(*args, **kwargs)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/views/generic/edit.py", line 142, in post
    return self.form_valid(form)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/contrib/auth/views.py", line 235, in form_valid
    form.save(**opts)
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 323, in save
    self.send_mail(
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 273, in send_mail
    email_message.send()
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/home/ulefr01/.virtualenvs/env_adressen/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 69, in open
    self.connection.login(self.username, self.password)
  File "/usr/lib/python3.8/smtplib.py", line 734, in login
    raise last_exception
  File "/usr/lib/python3.8/smtplib.py", line 723, in login
    (code, resp) = self.auth(
  File "/usr/lib/python3.8/smtplib.py", line 646, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials 15sm14978397qko.119 - gsmtp')
2021-02-10 13:30:36,463: Internal Server Error: /accounts/password_reset/

[formatted by admin]

Are you using an app-specific password, as described on the help page that @piotr linked to earlier on? You mentioned "less secure apps", but that's a different thing to app-specific passwords.