Djoser连接错误

时间:2016-04-15 11:19:32

标签: python django

我在使用Djoser密码重置模块处理我正在开发的API时遇到了一些问题。

在我的DJANGO设置中:

EMAIL_USE_TLS=True
EMAIL_HOST=smtp.gmail.com
EMAIL_HOST_USER=<my_username@gmail.com>
EMAIL_HOST_PASSWORD=<my_password>
EMAIL_PORT=587

对于我的Djoser设置:

 DJOSER = {
        'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
    }

调用堆栈:

Internal Server Error: /api/auth/password/reset/
Traceback (most recent call last):
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "vendor/djoser/djoser/utils.py", line 57, in post
    return self.action(serializer)
  File "vendor/djoser/djoser/views.py", line 116, in action
    self.send_email(**self.get_send_email_kwargs(user))
  File "vendor/djoser/djoser/utils.py", line 72, in send_email
    send_email(to_email, from_email, context, **self.get_send_email_extras())
  File "vendor/djoser/djoser/utils.py", line 49, in send_email
    email_message.send()
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/mail/message.py", line 292, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.4/smtplib.py", line 242, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.4/smtplib.py", line 321, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.4/smtplib.py", line 292, in _get_socket
    self.source_address)
  File "/usr/lib/python3.4/socket.py", line 512, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 503, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Internal Server Error: /api/auth/password/reset/
Traceback (most recent call last):
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "vendor/djoser/djoser/utils.py", line 57, in post
    return self.action(serializer)
  File "vendor/djoser/djoser/views.py", line 116, in action
    self.send_email(**self.get_send_email_kwargs(user))
  File "vendor/djoser/djoser/utils.py", line 72, in send_email
    send_email(to_email, from_email, context, **self.get_send_email_extras())
  File "vendor/djoser/djoser/utils.py", line 49, in send_email
    email_message.send()
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/mail/message.py", line 292, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/home/metpetdb/.virtualenvs/api/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.4/smtplib.py", line 242, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.4/smtplib.py", line 321, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.4/smtplib.py", line 292, in _get_socket
    self.source_address)
  File "/usr/lib/python3.4/socket.py", line 512, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 503, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

我是使用Djoser模块的新手,我花了太多时间试图找出连接错误的原因。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

您是否可能需要包含完整的DJOSER设置?

 DJOSER = {
    'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
    'ACTIVATION_URL': '#/activate/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    'SERIALIZERS': {},
 }

另外,我错误地将我的电子邮件配置放在引号中,即EMAIL_HOST = smtp.gmail.com而不是EMAIL_HOST ='smtp.gmail.com'