G
G
gh0sty2019-10-11 17:12:27
Django
gh0sty, 2019-10-11 17:12:27

How to fix ConnectionAbortedError in django?

In general, I send an e-mail to the user, but the traceback gives an error.

ConnectionAbortedError: [WinError 10053] A program on your host machine aborted an established connection

And before that, an error in message (some function returns a bool, not the required result):
AttributeError: 'bool' object has no attribute 'splitlines'

I'm not sure about my view, because new to django send_mail(). But the forums write - the problem is in the bakery.
Here is the view:
def profile_email_update(request, username):
    if username == request.user.username:
        ce = ProfileChangeEmailForm(request.POST)
        if ce.is_valid():
            user_id = User.objects.get(username=username)
            email = ce.cleaned_data['email']
            key_model = EmailVerification.objects.create(user=user_id, new_email=email)
            key_model.save()
            subj = 'Сменить мыло'
            mess = '<h1>Hi!!!!</h1>' \
                   'The link is <a href="127.0.0.1/email-confirm/{}/">here</a>'.format(key_model.key)
            send_mail(subj, mess, settings.EMAIL_HOST_USER, [email], fail_silently=False, html_message=True)
            return JsonResponse({'success': True})
        return JsonResponse({
            'success': False,
            'errors': dict(ce.errors.items()),
        })

Here is the traceback:
Traceback (most recent call last):
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\gh0st\PycharmProjects\ss\newSS\main\views.py", line 779, in profile_email_update
    send_mail(subj, mess, settings.EMAIL_HOST_USER, [email], fail_silently=False, html_message=True)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\__init__.py", line 60, in send_mail
    return mail.send()
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 291, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\backends\smtp.py", line 110, in send_messages
    sent = self._send(message)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\backends\smtp.py", line 124, in _send
    message = email_message.message()
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 254, in message
    msg = self._create_message(msg)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 443, in _create_message
    return self._create_attachments(self._create_alternatives(msg))
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 453, in _create_alternatives
    msg.attach(self._create_mime_attachment(*alternative))
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 368, in _create_mime_attachment
    attachment = SafeMIMEText(content, subtype, encoding)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 166, in __init__
    MIMEText.__init__(self, _text, _subtype=_subtype, _charset=_charset)
  File "C:\Users\gh0st\AppData\Local\Programs\Python\Python37-32\lib\email\mime\text.py", line 42, in __init__
    self.set_payload(_text, _charset)
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\mail\message.py", line 176, in set_payload
    for l in payload.splitlines()
AttributeError: 'bool' object has no attribute 'splitlines'
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 7597)
Traceback (most recent call last):
  File "C:\Users\gh0st\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 650, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Users\gh0st\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Users\gh0st\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 720, in __init__
    self.handle()
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\servers\basehttp.py", line 171, in handle
    self.handle_one_request()
  File "C:\Users\gh0st\PycharmProjects\ss\venv\lib\site-packages\django\core\servers\basehttp.py", line 179, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "C:\Users\gh0st\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] Программа на вашем хост-компьютере разорвала установленное подключение

At the same time, when I sent through allauth - there are no problems.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JRazor, 2019-10-12
@gh0sty

https://docs.djangoproject.com/en/2.2/topics/email...
html_message must be a string, not a boolean value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question