anymail / django-anymail

Django email backends and webhooks for Amazon SES, Brevo (Sendinblue), MailerSend, Mailgun, Mailjet, Postmark, Postal, Resend, SendGrid, SparkPost, Unisender Go and more
https://anymail.dev
BSD 3-Clause "New" or "Revised" License
1.7k stars 131 forks source link

'Transport Endpoint is not connected' #248

Closed aliaksei135 closed 3 years ago

aliaksei135 commented 3 years ago

TEMPLATED_EMAIL_BACKEND = EMAIL_BACKEND

TEMPLATED_EMAIL_EMAIL_MESSAGE_CLASS = 'anymail.message.AnymailMessage' TEMPLATED_EMAIL_EMAIL_MULTIALTERNATIVES_CLASS = 'anymail.message.AnymailMessage'

* Django: 2.2.9, requests: 2.26.0, Python: 3.8.10

Tried disabling firewall, no luck. Not sure what this could be.

Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: Traceback (most recent call last): Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: httplib_response = self._make_request( Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self._validate_conn(conn) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: conn.connect() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connection.py", line 453, in connect Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: cert = self.sock.getpeercert() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/usr/lib/python3.8/ssl.py", line 1123, in getpeercert Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self._check_connected() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/usr/lib/python3.8/ssl.py", line 1088, in _check_connected Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self.getpeername() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: OSError: [Errno 107] Transport endpoint is not connected Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: During handling of the above exception, another exception occurred: Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: Traceback (most recent call last): Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: resp = conn.urlopen( Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: retries = retries.increment( Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 532, in increment Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: raise six.reraise(type(error), error, _stacktrace) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/packages/six.py", line 734, in reraise Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: raise value.with_traceback(tb) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: httplib_response = self._make_request( Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self._validate_conn(conn) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: conn.connect() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/urllib3/connection.py", line 453, in connect Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: cert = self.sock.getpeercert() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/usr/lib/python3.8/ssl.py", line 1123, in getpeercert Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self._check_connected() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/usr/lib/python3.8/ssl.py", line 1088, in _check_connected Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self.getpeername() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(107, 'Transport endpoint is not connected')) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: During handling of the above exception, another exception occurred: Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: Traceback (most recent call last): Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/anymail/backends/base_requests.py", line 72, in post_to_esp Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = self.session.request(params) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/requests/sessions.py", line 542, in request Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: resp = self.send(prep, send_kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/requests/sessions.py", line 655, in send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: r = adapter.send(request, kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/requests/adapters.py", line 498, in send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: raise ConnectionError(err, request=request) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: requests.exceptions.ConnectionError: ('Connection aborted.', OSError(107, 'Transport endpoint is not connected')) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: The above exception was the direct cause of the following exception: Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: Traceback (most recent call last): Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = get_response(request) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = self.process_exception_by_middleware(e, request) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = wrapped_callback(request, *callback_args, *callback_kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/usr/lib/python3.8/contextlib.py", line 75, in inner Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return func(args, kwds) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return self.dispatch(request, *args, kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 45, in _wrapper Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return bound_method(*args, *kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return view(request, args, kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/views.py", line 215, in dispatch Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return super(SignupView, self).dispatch(request, *args, *kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/views.py", line 78, in dispatch Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = super(RedirectAuthenticatedUserMixin, Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/views.py", line 191, in dispatch Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return super(CloseableSignupMixin, self).dispatch(request, Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return handler(request, args, **kwargs) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/views.py", line 104, in post Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = self.form_valid(form) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/views.py", line 233, in form_valid Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return complete_signup( Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/utils.py", line 188, in complete_signup Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return perform_login(request, user, Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/utils.py", line 152, in perform_login Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: send_email_confirmation(request, user, signup=signup) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/utils.py", line 322, in send_email_confirmation Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: email_address.send_confirmation(request, Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/models.py", line 58, in send_confirmation Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: confirmation.send(request, signup=signup) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/models.py", line 163, in send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: get_adapter(request).send_confirmation_mail(request, self, signup) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/adapter.py", line 448, in send_confirmation_mail Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: self.send_mail(email_template, Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/allauth/account/adapter.py", line 137, in send_mail Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: msg.send() Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/django/core/mail/message.py", line 291, in send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return self.get_connection(fail_silently).send_messages([self]) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/anymail/backends/base.py", line 94, in send_messages Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: sent = self._send(message) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/anymail/backends/base_requests.py", line 58, in _send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: return super()._send(message) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/anymail/backends/base.py", line 124, in _send Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: response = self.post_to_esp(payload, message) Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: File "/srv/sugc/venv/lib/python3.8/site-packages/anymail/backends/base_requests.py", line 77, in post_to_esp Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: raise exc_class( Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: anymail.backends.base_requests.AnymailRequestsAPIError: Error posting to https://api.mailjet.com/v3.1/send: Sep 18 13:31:21 ubuntu-s-1vcpu-2gb-lon1-01 gunicorn[1156]: requests.exceptions.ConnectionError: ('Connection aborted.', OSError(107, 'Transport endpoint is not connected'))

aliaksei135 commented 3 years ago

Seems specific to Mailjet, migrated to SendGrid now and all working.

medmunds commented 3 years ago

That's very odd. This seems like a low level networking issue, not something related to Anymail.

I wonder if you were experiencing (virtual) hardware issues or some other problem with outbound networking? Were other outgoing https requests from this machine working during the same time period? (And/or if you temporarily switch back to Mailjet, does the problem still occur?)

FWIW, Anymail live integration tests run weekly on Thursdays, and the one last Thursday was able to send through Mailjet without any problems.

aliaksei135 commented 3 years ago

Unfortunately I haven't had the bandwidth to test this. I'm happy to write it off as misconfiguration from my side since the integration tests pass.

I'll close this, thanks for your help!