My website has account management. One of my environment variables was the password to the host email that will be sending the reset password link as well as receiving messages from the contact page. After setting up the environment variables in pythonanywhere, I wanted to make sure that the password reset links were being sent to the logged in user from the host email.
So I logged into one of the accounts and tried to change its password. However, after entering the user email, I get a server error (500) instead of being redirected to a password reset confirmation page that tells the user to check their email for the password reset link. When I check the error logs, I get this :
2021-08-27 10:48:31,594: Internal Server Error: /reset_password/
Traceback (most recent call last):
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/views/generic/base.py", line 73, in view
return self.dispatch(request, *args, **kwargs)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/contrib/auth/views.py", line 222, in dispatch
return super().dispatch(*args, **kwargs)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/views/generic/base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/views/generic/edit.py", line 142, in post
return self.form_valid(form)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/contrib/auth/views.py", line 235, in form_valid
form.save(**opts)
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 323, in save
self.send_mail(
File "/home/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 273, in send_mail
email_message.send()
File "/home/iSow/.virtualenvs/isowvenv/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/iSow/.virtualenvs/isowvenv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/home/iSow/.virtualenvs/isowvenv/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: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt\n5.7.14 4zfgHrq9Tdy2IO7uqbGYVYQVJr3zRWtq_KGeMmtYZwV7D9FTB91wIT9YLYsKGPYwbuJ3B\n5.7.14 mgSdIRt9LaJbNJH4N7rXhOdYXLEwos_kjMGqmz-VqSMxet56dNrkzzMKr8W_XX6a>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 m5sm4328799qkn.33 - gsmtp')
On my local computer, everything works fine. I get the password reset link from the host email and any messages sent from the contact page is received in the inbox of the host email. So I am assuming it's something to do with the environment variables I set up in pythonanywhere. Though, when I ran echo $EMAIL_HOST_PASSWORD
in the bash console, I got the correct password.