#34732: UnicodeEncodeError on two tests in Python 3.12
--------------------------------------------------+------------------------
               Reporter:  Michel Alexandre Salim  |          Owner:  nobody
                   Type:  Uncategorized           |         Status:  new
              Component:  Uncategorized           |        Version:  dev
               Severity:  Normal                  |       Keywords:
           Triage Stage:  Unreviewed              |      Has patch:  0
    Needs documentation:  0                       |    Needs tests:  0
Patch needs improvement:  0                       |  Easy pickings:  0
                  UI/UX:  0                       |
--------------------------------------------------+------------------------
 When running the tests inside a virtual environment with Fedora 39's
 python3-3.12.0~b4-1.fc39.x86_64, there are currently two test failures
 left with the `test_sqlite` backend


 {{{
 ======================================================================
 ERROR: test_safe_mime_multipart
 (mail.tests.MailTests.test_safe_mime_multipart)
 Make sure headers can be set with a different encoding than utf-8 in
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 64, in forbid_multi_line_headers
     val.encode("ascii")
 UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in
 position 2: ordinal not in range(128)

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "/home/michel/src/github/django/django/tests/mail/tests.py", line
 504, in test_safe_mime_multipart
     msg.message()["To"],
     ^^^^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 266, in message
     self._set_list_header_if_not_empty(msg, "To", self.to)
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 431, in _set_list_header_if_not_empty
     msg[header] = value
     ~~~^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 188, in __setitem__
     name, val = forbid_multi_line_headers(name, val, self.encoding)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 67, in forbid_multi_line_headers
     val = ", ".join(
           ^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 68, in <genexpr>
     sanitize_address(addr, encoding) for addr in getaddresses((val,))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 101, in sanitize_address
     raise ValueError(f'Invalid address "{address}"')
 ValueError: Invalid address ""

 ======================================================================
 ERROR: test_unicode_address_header
 (mail.tests.MailTests.test_unicode_address_header)
 Regression for #11144 - When a to/from/cc header contains Unicode,
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 64, in forbid_multi_line_headers
     val.encode("ascii")
 UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in
 position 2: ordinal not in range(128)

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "/home/michel/src/github/django/django/tests/mail/tests.py", line
 461, in test_unicode_address_header
     email.message()["To"],
     ^^^^^^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 266, in message
     self._set_list_header_if_not_empty(msg, "To", self.to)
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 431, in _set_list_header_if_not_empty
     msg[header] = value
     ~~~^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 165, in __setitem__
     name, val = forbid_multi_line_headers(name, val, self.encoding)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 67, in forbid_multi_line_headers
     val = ", ".join(
           ^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 68, in <genexpr>
     sanitize_address(addr, encoding) for addr in getaddresses((val,))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File
 "/home/michel/src/github/django/django/django/core/mail/message.py", line
 101, in sanitize_address
     raise ValueError(f'Invalid address "{address}"')
 ValueError: Invalid address ""

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34732>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018979f01e0e-87223fc1-9cf0-400d-9946-79866e53803e-000000%40eu-central-1.amazonses.com.

Reply via email to