This appears to be a bug in python-apt. It fails to parse .sources files which contain a comment paragraph which is not connect to a source stanza (I think). I.e., this first scenario is fine:
root@mantic:~# cat /etc/apt/sources.list.d/ubuntu.sources # This comment is OK. Types: deb URIs: http://archive.ubuntu.com/ubuntu Suites: mantic mantic-updates Components: main universe Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: http://security.ubuntu.com/ubuntu Suites: mantic-security Components: main universe Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg root@mantic:~# python3 Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from aptsources.sourceslist import SourcesList >>> for e in SourcesList(deb822=True): ... print(str(e)) ... # This comment is OK. Types: deb URIs: http://archive.ubuntu.com/ubuntu Suites: mantic mantic-updates Components: main universe Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: http://security.ubuntu.com/ubuntu Suites: mantic-security Components: main universe Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg >>> As opposed to this, which fails: root@mantic:~# cat /etc/apt/sources.list.d/ubuntu.sources # This comment is NOT OK. # This comment is OK. Types: deb URIs: http://archive.ubuntu.com/ubuntu Suites: mantic mantic-updates Components: main universe Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: http://security.ubuntu.com/ubuntu Suites: mantic-security Components: main universe Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg root@mantic:~# python3 Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from aptsources.sourceslist import SourcesList >>> for e in SourcesList(deb822=True): ... print(str(e)) ... WARNING:root:could not open file '/etc/apt/sources.list.d/ubuntu.sources': Unable to parse section data >>> -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2047447 Title: No valid source.list found while upgrading from mantic to noble To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/python-apt/+bug/2047447/+subscriptions -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs