Error: ConnectionRefusedError at /accounts/login/

Hello, When I sign in new id, it has an issue. Could you please guide me to fix it?
error: ConnectionRefusedError at /accounts/login/ [Errno 111] Connection refused Request Method: POST Request URL: https://lists.klnpa.org/accounts/login/ Django Version: 4.2.19 Exception Type: ConnectionRefusedError Exception Value: [Errno 111] Connection refused Exception Location: /usr/lib64/python3.9/socket.py, line 844, in create_connection Raised during: allauth.account.views.LoginView Python Executable: /opt/mailman/venv/bin/uwsgi Python Version: 3.9.21 Python Path: ['.', '', '/etc/mailman3', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/opt/mailman/venv/lib64/python3.9/site-packages', '/opt/mailman/venv/lib/python3.9/site-packages']

On 2/25/25 12:29, Kim Sunggun via Mailman-users wrote:
Hello, When I sign in new id, it has an issue. Could you please guide me to fix it?
error: ConnectionRefusedError at /accounts/login/ [Errno 111] Connection refused Request Method: POST Request URL: https://lists.klnpa.org/accounts/login/ Django Version: 4.2.19 Exception Type: ConnectionRefusedError Exception Value: [Errno 111] Connection refused Exception Location: /usr/lib64/python3.9/socket.py, line 844, in create_connection Raised during: allauth.account.views.LoginView
What is your Django setting for EMAIL_BACKEND? Normally, this is
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
Depending on your outgoing MTA, you may need additional settings. See https://docs.djangoproject.com/en/5.1/topics/email/#django.core.mail.backend...
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

Hello,
/opt/mailman/venv/lib/python3.9/site-packages/django/conf/global_settings.py:EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" /opt/mailman/venv/lib/python3.9/site-packages/mailman_web/settings/base.py:EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
I installed mailman3 in rhel 9 based on https://docs.mailman3.org/en/latest/install/virtualenv.html#virtualenv-insta... I set up Postfix as the MTA. I added the code as mentioned in the document.
unknown_local_recipient_reject_code = 550 owner_request_special = no
transport_maps = hash:/opt/mailman/mm/var/data/postfix_lmtp local_recipient_maps = hash:/opt/mailman/mm/var/data/postfix_lmtp relay_domains = hash:/opt/mailman/mm/var/data/postfix_domains

On 2/27/25 05:44, Kim Sunggun via Mailman-users wrote:
Hello,
/opt/mailman/venv/lib/python3.9/site-packages/django/conf/global_settings.py:EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" /opt/mailman/venv/lib/python3.9/site-packages/mailman_web/settings/base.py:EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
OK.
I installed mailman3 in rhel 9 based on https://docs.mailman3.org/en/latest/install/virtualenv.html#virtualenv-insta... I set up Postfix as the MTA. I added the code as mentioned in the document.
unknown_local_recipient_reject_code = 550 owner_request_special = no
transport_maps = hash:/opt/mailman/mm/var/data/postfix_lmtp local_recipient_maps = hash:/opt/mailman/mm/var/data/postfix_lmtp relay_domains = hash:/opt/mailman/mm/var/data/postfix_domains
These are good but not relevant to your issue. They affect delivery of incoming mail to Mailman. Your issue is with outgoing mail from Django.
There are various settings that affect this SMTP connection as described at https://docs.djangoproject.com/en/5.1/topics/email/#smtp-backend
The defaults are
EMAIL_HOST = "localhost" EMAIL_PORT = 25
and for the optional settings
EMAIL_HOST_USER = "" EMAIL_HOST_PASSWORD = "" EMAIL_USE_TLS = False EMAIL_USE_SSL = False EMAIL_SSL_CERTFILE = None EMAIL_SSL_KEYFILE = None
Have you set any of those to other than default in your Django settings? If not, what do you get if you run this python snippet as the Mailman user
import smtplib
connection = smtplib.SMTP(host='localhost', port=25)
If you have, you can specify them as args to smtplib.SMTP, e.g.
connection = smtplib.SMTP(host='localhost', port=25, username='...',
password='...')
or if EMAIL_USE_SSL is True,
connection = smtplib.SMTP_SSL(host='localhost', port=25, username='...',
password='...', ssl_keyfile='...', ssl_certfile='...')
See https://github.com/django/django/blob/ea1e3703bee28bfbe4f32ceb39ad31763353b1...
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

script: #!/usr/bin/env python3 import smtplib
host = 'localhost' port = 25 connection = smtplib.SMTP(host=host, port=port) connection.ehlo() connection.quit()
result: Traceback (most recent call last): File "/opt/mailman/./testone.py", line 7, in <module> connection = smtplib.SMTP(host=host, port=port) File "/usr/lib64/python3.9/smtplib.py", line 255, in __init__ (code, msg) = self.connect(host, port) File "/usr/lib64/python3.9/smtplib.py", line 341, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib64/python3.9/smtplib.py", line 312, in _get_socket return socket.create_connection((host, port), timeout, File "/usr/lib64/python3.9/socket.py", line 856, in create_connection raise err File "/usr/lib64/python3.9/socket.py", line 844, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

On 2/27/25 12:36, Kim Sunggun via Mailman-users wrote:
script: #!/usr/bin/env python3 import smtplib
host = 'localhost' port = 25 connection = smtplib.SMTP(host=host, port=port) connection.ehlo() connection.quit()
result: Traceback (most recent call last): File "/opt/mailman/./testone.py", line 7, in <module> connection = smtplib.SMTP(host=host, port=port) File "/usr/lib64/python3.9/smtplib.py", line 255, in __init__ (code, msg) = self.connect(host, port) File "/usr/lib64/python3.9/smtplib.py", line 341, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib64/python3.9/smtplib.py", line 312, in _get_socket return socket.create_connection((host, port), timeout, File "/usr/lib64/python3.9/socket.py", line 856, in create_connection raise err File "/usr/lib64/python3.9/socket.py", line 844, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
So you are doing the same thing Django allauth is doing with the same result. Do you even have an MTA listening on localhost, port 25?
You need to figure out what settings you need to be able to connect to your outgoing MTA and set
EMAIL_HOST EMAIL_PORT
and maybe some of
EMAIL_HOST_USER EMAIL_HOST_PASSWORD EMAIL_USE_TLS EMAIL_USE_SSL EMAIL_SSL_CERTFILE EMAIL_SSL_KEYFILE
appropriately so you can connect to the MTA. If outgoing mail from Mailman works, look in the [mta] section in mailman.cfg for the appropriate settings.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

Have you set any of those to other than default in your Django settings? everything is default.

Kim Sunggun via Mailman-users writes:
Have you set any of those to other than default in your Django settings? everything is default.
What we're doing is not relevant because we're not trying to connect to your MTA. Some of us do because our MTAs expect authentication or are running on a different port for some reason. Many of us don't because our MTAs use the defaults too, at least for local connections.
The question *you* need to figure out is why won't your MTA talk to Django *at all*? Any number of reasons, in approximate order of when they arise in the connection process:
- You can't get there from here because of a firewall (very unlikely on localhost).
- The MTA isn't listening on that port at that address. The port might work at a different address, another port might work at that address, or maybe both are different. As Mark recommended, check the Mailman configuration at [mta]. If it says anything about smtp_host or smtp_port, use those in your Django configuration too. If it doesn't, they default to 127.0.0.1:25 or localhost:25, and the Django defaults should be OK.
- The MTA is listening for IPv6 (eg, [::1]). If you specify "localhost", maybe it automatically tries IPv6, but maybe it doesn't. If Django is assuming 127.0.0.1, it won't try [::1].
- The MTA expects mandatory TLS (usually port = 465).
- The MTA expects negotiated TLS (STARTTLS), mostly on port 589 but some sites require it on port 25.
- The MTA expects authentication in TLS initialization (don't ask me, I've never set this up). I don't recall whether generic SASL applies here, although I know you can use X.509 certificates. (SASL is the authentication protocol that most MTAs use *after* the connection is established, but you aren't getting that far.)
I wouldn't be surprised if there are other possible issues, but that's enough for now. ;-)
Your MTA logs should show that there was a connection attempt at the right time from the right host (probably localhost), and give the point at which the connection failed and maybe a reason why. If there's nothing at all in the MTA log, the problem is #1 above.
participants (3)
-
Kim Sunggun
-
Mark Sapiro
-
Stephen J. Turnbull