InsaLan / backend-insalan.fr

Backend of the insalan website
MIT License
2 stars 0 forks source link

Python 3.12 SSL module removed "keyfile" in SMTP_SSL #134

Open Lymkwi opened 8 months ago

Lymkwi commented 8 months ago

At the moment, trying to send an email with the current version of Django makes the backend explode:

  File "/app/insalan/user/views.py", line 213, in post
    UserMailer.send_password_reset(user_object)
  File "/app/insalan/user/models.py", line 180, in send_password_reset
    send_mail(
  File "/usr/local/lib/python3.12/site-packages/django/core/mail/__init__.py", line 87, in send_mail
    return mail.send()
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/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.12/site-packages/django/core/mail/backends/smtp.py", line 124, in send_messages
    new_conn_created = self.open()
                       ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/django/core/mail/backends/smtp.py", line 80, in open
    self.connection = self.connection_class(
                      ^^^^^^^^^^^^^^^^^^^^^^
TypeError: SMTP_SSL.__init__() got an unexpected keyword argument 'keyfile'
[15/Feb/2024 16:27:42] "POST /v1/user/password-reset/ask/ HTTP/1.0" 500 109706

As it turns out, smtplib.SMTP_SSL which is used by Django changed its code and now Django 4.2.7 has to follow.

KwikKill commented 8 months ago

This is already fixed on prod server, python 3.12 is not compatible with our django version. Using 3.11 is working fine, this was a fast fix, i forgot to push it to dev.

Lymkwi commented 8 months ago

Alright, that makes sense.

Actually, we should look into upgrading django, django_rest_framework and djongo as much as possible. For one of them (djongo), the releases seem dead, and a fork (djongo5) has been created to provide support for Django 5.X.

KwikKill commented 8 months ago

Yes, this is planned but for now, the easiest fix was to stay in python3.11 until the end of the LAN.