PEP 594 removed the so-called dead batteries in Python 3.13 (October 2024). The deleted modules include cgi, cgitb, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib, chunk, audioop and aifc. They were deprecated with a warning in 3.11 and 3.12, then dropped entirely, so an application that only ever ran with warnings suppressed breaks at import time on 3.13.
The usual first symptom is not your own code. cgi is pulled in by older versions of several HTTP and multipart libraries, and imghdr by older image handling code, so the traceback points at a dependency.
Audit before upgrading by grepping the installed site-packages tree for those module names, or run the test suite on 3.12 with -W error::DeprecationWarning, which turns every remaining use into a failure while the modules still exist. PyPI carries standalone backports for several of them, published under the standard- prefix by the legacy-cgi and related projects.