简体   繁体   中英

django password reset does not work on server but works on local machine

I am using gmail password manager to generate password. When I try to send email for password reset on sever I get 500 Error. This same format works when I try to send password reset email locally.

These are my settings in settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = config['EMAIL_USER']
EMAIL_HOST_PASSWORD = config['EMAIL_PASS']
DEFAULT_FROM_EMAIL = config['EMAIL_USER']

I have even tried to hard code email and password, but that still does not work.

I am using apache2 and here is my configurations:

src => all the project files, recipe_app => project settings

src
|__recipe_app
   |__settings.py
   |__wsgi.py
Alias /static /home/<user>/src/static
<Directory /home/<user>/src/static>
    Require all granted
</Directory>

Alias /media /home/<user>/src/media
<Directory /home/<user>/src/media>
    Require all granted
</Directory>

<Directory /home/<user>/src/recipe_app>
    <Files wsgi.py>
        Require all granted
</Files>
</Directory>

WSGIScriptAlias / /home/<user>/src/recipe_app/wsgi.py
WSGIDaemonProcess recipe_app python-path=/home/<user>/src python-home=/home/<user>/src/venv
WSGIProcessGroup recipe_app

EDIT: Error from /var/log/apache2/error.log

[Sun Nov 15 17:11:13.398934 2020] [wsgi:error] [pid 59359:tid 140426823104064] [remote 73.24.24.160:51419] Not Found: /favicon.ico
[Sun Nov 15 17:15:39.443147 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421] Internal Server Error: /password-reset/
[Sun Nov 15 17:15:39.443217 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421] Traceback (most recent call last):
[Sun Nov 15 17:15:39.443224 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
[Sun Nov 15 17:15:39.443229 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     response = get_response(request)
[Sun Nov 15 17:15:39.443233 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
[Sun Nov 15 17:15:39.443237 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sun Nov 15 17:15:39.443241 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
[Sun Nov 15 17:15:39.443245 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return self.dispatch(request, *args, **kwargs)
[Sun Nov 15 17:15:39.443249 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
[Sun Nov 15 17:15:39.443253 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return bound_method(*args, **kwargs)
[Sun Nov 15 17:15:39.443257 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
[Sun Nov 15 17:15:39.443261 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     response = view_func(request, *args, **kwargs)
[Sun Nov 15 17:15:39.443264 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/views.py", line 222, in dispatch
[Sun Nov 15 17:15:39.443279 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return super().dispatch(*args, **kwargs)
[Sun Nov 15 17:15:39.443283 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
[Sun Nov 15 17:15:39.443287 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return handler(request, *args, **kwargs)
[Sun Nov 15 17:15:39.443290 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/views/generic/edit.py", line 142, in post
[Sun Nov 15 17:15:39.443294 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return self.form_valid(form)
[Sun Nov 15 17:15:39.443297 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/views.py", line 235, in form_valid
[Sun Nov 15 17:15:39.443301 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     form.save(**opts)
[Sun Nov 15 17:15:39.443304 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 323, in save
[Sun Nov 15 17:15:39.443308 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     self.send_mail(
[Sun Nov 15 17:15:39.443311 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 273, in send_mail
[Sun Nov 15 17:15:39.443315 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     email_message.send()
[Sun Nov 15 17:15:39.443318 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
[Sun Nov 15 17:15:39.443322 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return self.get_connection(fail_silently).send_messages([self])
[Sun Nov 15 17:15:39.443326 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
[Sun Nov 15 17:15:39.443330 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     new_conn_created = self.open()
[Sun Nov 15 17:15:39.443333 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/home/<user>/src/venv/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 62, in open
[Sun Nov 15 17:15:39.443337 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     self.connection = self.connection_class(self.host, self.port, **connection_params)
[Sun Nov 15 17:15:39.443340 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py", line 253, in __init__
[Sun Nov 15 17:15:39.443340 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py">
[Sun Nov 15 17:15:39.443344 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     (code, msg) = self.connect(host, post, port)
[Sun Nov 15 17:15:39.443347 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py", line 339, in connect
[Sun Nov 15 17:15:39.443351 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     self.sock = self._get_socket(host, port, self.timeout)
[Sun Nov 15 17:15:39.443354 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/smtplib.py", line 308, in _get_socket
[Sun Nov 15 17:15:39.443358 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     return socket.create_connection((host, port), timeout,
[Sun Nov 15 17:15:39.443365 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/socket.py", line 808, in create_connection
[Sun Nov 15 17:15:39.443369 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     raise err
[Sun Nov 15 17:15:39.443372 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]   File "/usr/lib/python3.8/socket.py", line 796, in create_connection
[Sun Nov 15 17:15:39.443376 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421]     sock.connect(sa)
[Sun Nov 15 17:15:39.443379 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51421] TimeoutError: [Errno 110] Connection timed out
[Sun Nov 15 17:26:36.683349 2020] [wsgi:error] [pid 59359:tid 140426923816512] [remote 73.24.24.160:51528] Not Found: /favicon.ico
[Sun Nov 15 17:27:04.919592 2020] [core:warn] [pid 59358:tid 140426973744448] AH00045: child process 59360 still did not exit, sending a SIGTERM
[Sun Nov 15 17:27:06.594680 2020] [wsgi:error] [pid 59360:tid 140426740708928] [client 73.24.24.160:51525] Truncated or oversized response headers received from daemon process 'recipe_app': /home/<user>/src/recipe_app/wsgi.py, referer: https://www.myawesomerecipeapp.com/password-reseet/

Port status: ports

It turns out Linode blocks mailing services due to spam, so you have to open a ticket to enable mailing feature. Here is the source: source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM