python - django密码重置在服务器上不起作用,但在本地机器上起作用
问题描述
我正在使用 gmail 密码管理器生成密码。当我尝试在服务器上发送电子邮件以重置密码时,我收到 500 错误。当我尝试在本地发送密码重置电子邮件时,这种格式也有效。
这些是我在 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']
我什至尝试对电子邮件和密码进行硬编码,但这仍然不起作用。
我正在使用 apache2,这是我的配置:
src => 所有项目文件,recipe_app => 项目设置
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
编辑: 来自 /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/
端口状态: 端口
解决方案
事实证明,由于垃圾邮件,Linode 会阻止邮件服务,因此您必须打开票证才能启用邮件功能。这是来源:来源
推荐阅读
- java - Firefox 无头在无头 redhat linux 机器上崩溃
- paypal - 将 PayPal 智能支付 API 与旧的 Express Checkout API 集成
- r - 如何在列表上应用函数并返回向量?R
- javascript - 根据增量道具值更改列表元素的类名 - ReactJS
- angular - angular2-multiselect-dropdown badgeShowLimit 选项不起作用
- docker - Traefik 2.0 - 取决于 PathPrefix 的相同服务的转发身份验证和基本身份验证
- jquery - Jquery Table2Excel 模块:工作,但 Excel 抛出错误
- c# - WPF C# 使用绑定在 DataGrid 中显示 Observable 集合
- c# - WPF MVVM 依赖注入构造函数异常
- python - 拆分多个分配不会产生相同的输出