使用非常基本的密码重置时出现Errno 111连接被拒绝错误

10

我是一个初学者,正在学习Django。目前我正在尝试使用admin password_reset函数实现密码恢复,但是我遇到了一个错误。根据我阅读的其他人遇到类似问题的经验,这可能是某种端口/套接字问题,但是我不确定如何更改或修复它。需要说明的是,我是在虚拟Ubuntu上运行的,不确定是否与此有任何关系。

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/password_reset/
Django Version: 1.1.4
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'homework.events',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in   get_response
  99.                     response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/views.py" in password_reset
  116.             form.save(**opts)
    File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/forms.py" in save
  136.                 t.render(Context(c)), None, [user.email])
    File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py" in send_mail
  407.                         connection=connection).send()
    File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py" in send
  281.         return self.get_connection(fail_silently).send_messages([self])
    File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py" in send_messages
  179.         new_conn_created = self.open()
    File "/usr/local/lib/python2.6/dist-packages/django/core/mail.py" in open
  144.                                            local_hostname=DNS_NAME.get_fqdn())
    File "/usr/lib/python2.6/smtplib.py" in __init__
  239.             (code, msg) = self.connect(host, port)
    File "/usr/lib/python2.6/smtplib.py" in connect
  295.         self.sock = self._get_socket(host, port, self.timeout)
    File "/usr/lib/python2.6/smtplib.py" in _get_socket
  273.         return socket.create_connection((port, host), timeout)
    File "/usr/lib/python2.6/socket.py" in create_connection
  561.     raise error, msg

Exception Type: error at /admin/password_reset/
Exception Value: [Errno 111] Connection refused

我知道我可能需要更改端口,但不确定如何做才能解决错误。另外,对于代码的编辑不太好我表示歉意。提前感谢。

相关问题:https://dev59.com/o2025IYBdhLWcg3wyJCV - hcs42
6个回答

9
密码重置功能尝试发送电子邮件。
您会收到此错误,是因为它尝试连接到电子邮件服务器,但连接被拒绝。

4

密码重置功能需要SMTP服务器发送重置电子邮件。您可以设置SMTP服务器以发送电子邮件,或选择其他不需要发送电子邮件的函数,例如set_password函数。


2

请查看电子邮件后端以在开发模式下测试您的电子邮件。您可以将其打印到控制台或文件中。或者,您需要设置一个SMTP服务器来发送出站邮件。


链接对我来说无法使用。 - The_spider

0

发送电子邮件检查密码重置。删除或注释EMAIL BACKEND。添加并填写详细信息,它将起作用。

# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'xxxxxxxxxxx@gmail.com'
EMAIL_HOST_PASSWORD ='xxxxx'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

0

我面临着同样的问题。因为我忘记在 settings.py 文件中添加 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 行。


0
EMAIL_BACKEND - 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST - 'smtp.gmail.com'
EMAIL_PORT - 587
EMAIL_USE_TLS - True
EMAIL_HOST_USER - "you@gmail.com"
EMAIL_HOST_PASSWORD - "get it from gmail app password bt setting 2 step authentication"

use = for - while using this code in settings.py

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接