Home > database >  How to fix error when sending mail with django in docker container? (Cannot assign requested address
How to fix error when sending mail with django in docker container? (Cannot assign requested address

Time:10-10

I'm getting an error when sending a letter both in Celery, as in the shell itself. Without the docker itself, there is no such error on the local computer, but there is on the server.

Error:

    send_mail('test', 'test msg', '[email protected]', ['[email protected]'])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/django/core/mail/__init__.py", line 87, in send_mail
    return mail.send()
  File "/usr/local/lib/python3.10/site-packages/django/core/mail/message.py", line 298, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python3.10/site-packages/django/core/mail/backends/smtp.py", line 124, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python3.10/site-packages/django/core/mail/backends/smtp.py", line 80, in open
    self.connection = self.connection_class(
  File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.10/smtplib.py", line 341, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.10/smtplib.py", line 312, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address

I looked through the other answers and didn't find anything helpful. I have a password configured, this error occurs in the docker.

CodePudding user response:

OSError: [Errno 99] Cannot assign requested address this means the provide ip/port is already taken.Change your ip/port and try again

find docker-compose.yml

version: '3.8'
services:
  web:
    build: .
    restart: unless-stopped
    ports: ['192.107.1.2:8000:8000'] # <-- change IP and port here
  

Try this

  • Related