#1082091 unattended-upgrades: Sending email report fails due to "HeaderWriteError" missing from Python mod. email.errors

#1082091#5
Date:
2024-09-18 09:29:15 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?

unattended upgrade doing its job, configured to send email to local root as

  Unattended-Upgrade::Mail "root";

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

Letting unattended upgrade do its automatic background job.

   * What was the outcome of this action?

The upgrade itself seems to have completed OK, but the final mail was not
sent due to the following Python error reported in
/var/log/unattended-upgrades/unattended-upgrades.log:
------------------------- snip -------------------------
2024-09-18 10:56:42,001 ERROR An error occurred: cannot import name 'HeaderWriteError' from 'email.errors' (/usr/lib/python3.12/email/errors.py)
Traceback (most recent call last):
  File "/usr/bin/unattended-upgrade", line 2246, in main
    send_summary_mail(res.pkgs, res.success, res.result_str,
  File "/usr/bin/unattended-upgrade", line 1728, in send_summary_mail
    ret = _send_mail_using_sendmail(from_email, to_email, subject, body)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/unattended-upgrade", line 1624, in _send_mail_using_sendmail
    sendmail.stdin.write(msg.as_string())
                         ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/email/message.py", line 181, in as_string
    from email.generator import Generator
  File "/usr/lib/python3.12/email/generator.py", line 17, in <module>
    from email.errors import HeaderWriteError
ImportError: cannot import name 'HeaderWriteError' from 'email.errors' (/usr/lib/python3.12/email/errors.py)
------------------------- snip -------------------------

   * What outcome did you expect instead?

Get a mail with the upgrade results.

   * Background information

This is most likely not a bug in u-u itself, but rather some dependency
issue.  It should be related to a missing fix for Python bug
https://github.com/python/cpython/issues/121650.

#1082091#10
Date:
2024-09-18 09:42:59 UTC
From:
To:
Forgot to add information on the relevant (?) Python package:

[~]$ dpkg -S /usr/lib/python3.12/email/errors.py
libpython3.12-minimal:amd64: /usr/lib/python3.12/email/errors.py

[~]$ aptitude show libpython3.12-minimal
Package: libpython3.12-minimal
Version: 3.12.6-1
State: installed
Automatically installed: yes
Multi-Arch: same
Priority: optional
Section: python
Maintainer: Matthias Klose <doko@debian.org>
Architecture: amd64
Uncompressed Size: 5,299 k
Depends: libc6 (>= 2.14), libssl3t64 (>= 3.3.0)
Recommends: libpython3.12-stdlib
Conflicts: binfmt-support (< 1.1.2)
Description: Minimal subset of the Python language (version 3.12)
 This package contains some essential modules. It is normally not used on it's
 own, but as a dependency of python3.12-minimal.

#1082091#15
Date:
2024-09-18 09:59:31 UTC
From:
To:
Ah, this is probably a one-time thing only, since file /usr/lib/python3.12/email/errors.py
actually already contains that Python fix on my system:
------------------------- snip ------------------------- [...] class CharsetError(MessageError): """An illegal charset was given.""" class HeaderWriteError(MessageError): """Error while writing headers.""" # These are parsing defects which the parser was able to work around. class MessageDefect(ValueError): [...] ------------------------- snip ------------------------- Leaving it to you whether you'd like to do something about this issue or not. For the record, the order of the package upgrades done by unattended-upgrade during the run where sending mail failed was as follows:
------------------------- snip ------------------------- [...] Log started: 2024-09-18 10:51:15 (Reading database ... 101329 files and directories currently installed.) Preparing to unpack .../python3.12-venv_3.12.6-1_amd64.deb ... Unpacking python3.12-venv (3.12.6-1) over (3.12.4-3) ... Preparing to unpack .../libpython3.12t64_3.12.6-1_amd64.deb ... Unpacking libpython3.12t64:amd64 (3.12.6-1) over (3.12.4-3) ... Preparing to unpack .../libssl3t64_3.3.2-1_amd64.deb ... Unpacking libssl3t64:amd64 (3.3.2-1) over (3.2.2-1) ... Selecting previously unselected package openssl-provider-legacy. Preparing to unpack .../openssl-provider-legacy_3.3.2-1_amd64.deb ... Unpacking openssl-provider-legacy (3.3.2-1) ... Setting up libssl3t64:amd64 (3.3.2-1) ... Setting up openssl-provider-legacy (3.3.2-1) ... (Reading database ... 101333 files and directories currently installed.) Preparing to unpack .../python3.12_3.12.6-1_amd64.deb ... Unpacking python3.12 (3.12.6-1) over (3.12.4-3) ... Preparing to unpack .../libpython3.12-stdlib_3.12.6-1_amd64.deb ... Unpacking libpython3.12-stdlib:amd64 (3.12.6-1) over (3.12.4-3) ... Preparing to unpack .../python3.12-minimal_3.12.6-1_amd64.deb ... Unpacking python3.12-minimal (3.12.6-1) over (3.12.4-3) ... Preparing to unpack .../libpython3.12-minimal_3.12.6-1_amd64.deb ... Unpacking libpython3.12-minimal:amd64 (3.12.6-1) over (3.12.4-3) ... Preparing to unpack .../openssl_3.3.2-1_amd64.deb ... Unpacking openssl (3.3.2-1) over (3.2.2-1) ... Setting up libpython3.12-minimal:amd64 (3.12.6-1) ... Setting up openssl (3.3.2-1) ... Installing new version of config file /etc/ssl/openssl.cnf ... Setting up python3.12-minimal (3.12.6-1) ... Setting up libpython3.12-stdlib:amd64 (3.12.6-1) ... Setting up python3.12 (3.12.6-1) ... Setting up libpython3.12t64:amd64 (3.12.6-1) ... Setting up python3.12-venv (3.12.6-1) ... Processing triggers for systemd (256.5-1) ... Processing triggers for man-db (2.12.1-3) ... Processing triggers for desktop-file-utils (0.27-2) ... Processing triggers for libc-bin (2.39-7) ... Log ended: 2024-09-18 10:51:19 [...] Log started: 2024-09-18 10:53:14 Preconfiguring packages ... Preconfiguring packages ... (Reading database ... 101505 files and directories currently installed.) Preparing to unpack .../unattended-upgrades_2.11+nmu1_all.deb ... Unpacking unattended-upgrades (2.11+nmu1) over (2.11) ... dpkg: warning: unable to delete old directory '/lib/systemd/system-sleep': Directory not empty Setting up unattended-upgrades (2.11+nmu1) ... Processing triggers for man-db (2.12.1-3) ... Log ended: 2024-09-18 10:53:15 [...] ------------------------- snip -------------------------