ONVIF fails to load module 'cgi' since core update

Hi, my Onvif integration has stopped working since the latest (Hassio Core-2024.12.0) update.

I’m getting the following error in the logs…

Logger: homeassistant.setup
Source: setup.py:334
First occurred: 5 December 2024 at 23:18:47 (2 occurrences)
Last logged: 5 December 2024 at 23:18:55

    Setup failed for 'onvif': Unable to import component: No module named 'cgi'
    Setup failed for custom integration 'nationalrailuk': Unable to import component: No module named 'cgi'

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1034, in async_get_component
    self._component_future.result()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1014, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._get_component, True
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1074, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/onvif/__init__.py", line 9, in <module>
    from onvif.exceptions import ONVIFError
  File "/usr/local/lib/python3.13/site-packages/onvif/__init__.py", line 2, in <module>
    import zeep
  File "/usr/local/lib/python3.13/site-packages/zeep/__init__.py", line 1, in <module>
    from zeep.client import AsyncClient, CachingClient, Client
  File "/usr/local/lib/python3.13/site-packages/zeep/client.py", line 6, in <module>
    from zeep.transports import AsyncTransport, Transport
  File "/usr/local/lib/python3.13/site-packages/zeep/transports.py", line 11, in <module>
    from zeep.utils import get_media_type, get_version
  File "/usr/local/lib/python3.13/site-packages/zeep/utils.py", line 1, in <module>
    import cgi
ModuleNotFoundError: No module named 'cgi'

The crux of the issue appears to be ModuleNotFoundError: No module named 'cgi'.

I have NO idea why, but i just restarted (5th time today), and it’s all started working. I’m extremely confused why.

I’m running into something similar, although in my case it prevents HA from starting up:

s6-rc: info: service legacy-services successfully started
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 192, in main
    from . import config, runner
  File "/usr/src/homeassistant/homeassistant/runner.py", line 16, in <module>
    from . import bootstrap
  File "/usr/src/homeassistant/homeassistant/bootstrap.py", line 27, in <module>
    from . import (
    ...<6 lines>...
    )
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 33, in <module>
    from .components import persistent_notification
  File "/usr/src/homeassistant/homeassistant/components/persistent_notification/__init__.py", line 14, in <module>
    from homeassistant.components import websocket_api
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/__init__.py", line 12, in <module>
    from . import commands, connection, const, decorators, http, messages  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/http.py", line 16, in <module>
    from homeassistant.components.http import KEY_HASS, HomeAssistantView
  File "/usr/src/homeassistant/homeassistant/components/http/__init__.py", line 50, in <module>
    from homeassistant.helpers.network import NoURLAvailableError, get_url
  File "/usr/src/homeassistant/homeassistant/helpers/network.py", line 10, in <module>
    from hass_nabucasa import remote
  File "/usr/local/lib/python3.13/site-packages/hass_nabucasa/__init__.py", line 18, in <module>
    from .auth import CloudError, CognitoAuth
  File "/usr/local/lib/python3.13/site-packages/hass_nabucasa/auth.py", line 12, in <module>
    import boto3
  File "/usr/local/lib/python3.13/site-packages/boto3/__init__.py", line 17, in <module>
    from boto3.session import Session
  File "/usr/local/lib/python3.13/site-packages/boto3/session.py", line 17, in <module>
    import botocore.session
  File "/usr/local/lib/python3.13/site-packages/botocore/session.py", line 26, in <module>
    import botocore.client
  File "/usr/local/lib/python3.13/site-packages/botocore/client.py", line 15, in <module>
    from botocore import waiter, xform_name
  File "/usr/local/lib/python3.13/site-packages/botocore/waiter.py", line 18, in <module>
    from botocore.docs.docstring import WaiterDocstring
  File "/usr/local/lib/python3.13/site-packages/botocore/docs/__init__.py", line 15, in <module>
    from botocore.docs.service import ServiceDocumenter
  File "/usr/local/lib/python3.13/site-packages/botocore/docs/service.py", line 14, in <module>
    from botocore.docs.client import ClientDocumenter, ClientExceptionsDocumenter
  File "/usr/local/lib/python3.13/site-packages/botocore/docs/client.py", line 14, in <module>
    from botocore.docs.example import ResponseExampleDocumenter
  File "/usr/local/lib/python3.13/site-packages/botocore/docs/example.py", line 13, in <module>
    from botocore.docs.shape import ShapeDocumenter
  File "/usr/local/lib/python3.13/site-packages/botocore/docs/shape.py", line 19, in <module>
    from botocore.utils import is_json_value_header
  File "/usr/local/lib/python3.13/site-packages/botocore/utils.py", line 15, in <module>
    import cgi
ModuleNotFoundError: No module named 'cgi'
[20:56:24] INFO: Home Assistant Core finish process exit code 1
[20:56:24] INFO: Home Assistant Core service shutdown

I’ve found using the HA cli to run ha core rebuild gets it back up, but restarts in general are a little more dicey now.

This is now being tracked in: