P
P
Peter Vorontsov2020-07-24 15:48:12
linux
Peter Vorontsov, 2020-07-24 15:48:12

Error on the server took too long to shut down and was killed ( OSError: [Errno 99] Cannot assign requested address), how to solve?

There is a view that sends data to the mail. On the local host (0.0.0.0) with debug=True and False it works well, but for some reason everything broke on the server and now it loads for a very long time and as a result 500 error.
And here's the miracle:
Application instance wait_for=._call_check_cancel() at /usr/local/lib/python3.7/asyncio/futures.py:351, ()]>> for connection took too long to shut down and was killed.
I thought that the port in the docker was closed, opened it, but all in vain

Python:

def ask_question(request):
    if request.method == "POST":
        name = request.POST.get('name_ask')
        phone_number = request.POST.get('phone_ask')
        message = "Как зовут клиента: "+name+".\n" \
                    "Телефон клиента: " + phone_number
        send_mail(
            'Нужна консультация!', message, '[email protected]', [
                '[email protected]'], fail_silently=False)
        messages.info(request, "Вы успешно подали заявку. Проверьте почтовый ящик")
    return HttpResponseRedirect('/')

settings.py:
spoiler

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
ACCOUNT_EMAIL_VERIFICATION = "none"
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'xxx'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_USE_SSL = True

<form style="margin-right: 1em" class="appointment-form ftco-animate" method="POST" action="../ask_question">
                        {% csrf_token %}
                        <br>
                        <input type="text" style="border-bottom: 1px solid rgba(10, 10, 10, 0.2) !important;" id="name_ask" name="name_ask" class="form-control" pattern="[А-Яа-я]{2, 20}" required placeholder="Как вас зовут?">
                       <input type="tel" style="border-bottom: 1px solid rgba(10, 10, 10, 0.2) !important;" id="phone_ask" name="phone_teach" pattern="^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$" required class="form-control" placeholder="Телефон">
                        <input type="submit" style="margin-top: 10px;border-radius: 0;color: #082567;font-size: 20px;width: 100%" value="Хочу пообщаться" class="btn btn-primary">
                                <p style="margin-bottom: 0; font-size: 10px; text-align: center" >Нажимая, вы принимаете <b>условия соглашения</b></p>
                    </form>


Traceback:
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
web_1 | response = get_response(request)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_1 | response = self.process_exception_by_middleware(e, request)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_1 | File "./talkapp/views.py", line 118, in send_request_view_teach
web_1 | user.email], fail_silently=False)
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/mail/__init__.py", line 60, in send_mail
web_1 | return mail.send()
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/mail/message.py", line 276, in send
web_1 | return self.get_connection(fail_silently).send_messages([self])
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
web_1 | new_conn_created = self.open()
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 62, in open
web_1 | self.connection = self.connection_class(self.host, self.port, **connection_params)
web_1 | File "/usr/local/lib/python3.7/smtplib.py", line 1031, in __init__
web_1 | source_address)
web_1 | File "/usr/local/lib/python3.7/smtplib.py", line 251, in __init__
web_1 | (code, msg) = self.connect(host, port)
web_1 | File "/usr/local/lib/python3.7/smtplib.py", line 336, in connect
web_1 | self.sock = self._get_socket(host, port, self.timeout)
web_1 | File "/usr/local/lib/python3.7/smtplib.py", line 1037, in _get_socket
web_1 | self.source_address)
web_1 | File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
web_1 | raise err
web_1 | File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
web_1 | sock.connect(sa)
web_1 | OSError: [Errno 99] Cannot assign requested address

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question