A
A
Artem Shishkov2020-05-09 20:04:14
Django
Artem Shishkov, 2020-05-09 20:04:14

TypeError in Celery, how can I fix it?

Good day!
Made mailing of letters through Celery. If I run this function through "delay", it gives an error:

TypeError: wrap_socket() got an unexpected keyword argument '_context'

If I run the function just like a regular function, emails are sent without errors...
Here is the function itself:
@shared_task
def send_email(path, context, user_email):  
    msg_html = render_to_string(path, context)
    msg = EmailMessage(
        subject=context['title'], 
        body=msg_html, 
        from_email=settings.EMAIL_HOST_USER, 
        bcc=(user_email,)
    )
    msg.content_subtype = "html"
    msg.send()

    return None

How can I fix it?

PS full traceback:
Traceback (most recent call last):
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\celery\app\trace.py", line 385, in trace_task
    R = retval = fun(*args, **kwargs)
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\celery\app\trace.py", line 650, in __protected_call__
    return self.run(*args, **kwargs)
  File "D:\!-Артем\github\UnitProject\unit\main\tasks.py", line 14, in send_email
    msg.send()
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\django\core\mail\message.py", line 276, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\django\core\mail\backends\smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\django_smtp_ssl.py", line 12, in open
    local_hostname=DNS_NAME.get_fqdn())
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\smtplib.py", line 1031, in __init__
    source_address)
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\smtplib.py", line 1039, in _get_socket
    server_hostname=self._host)
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\eventlet\green\ssl.py", line 437, in wrap_socket
    return GreenSSLSocket(sock, *a, _context=self, **kw)
  File "c:\users\r2-d2\appdata\local\programs\python\python37-32\lib\site-packages\eventlet\green\ssl.py", line 76, in __new__
    *args, **kw
TypeError: wrap_socket() got an unexpected keyword argument '_context'

PPS This error occurs when sending emails using ssl sending (EMAIL_USE_SSL = True). If you use TLS, then it runs without error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2020-05-10
@alternativshik

Isn't it? https://github.com/eventlet/eventlet/issues/526

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question