diff --git a/homeassistant/components/python_script/__init__.py b/homeassistant/components/python_script/__init__.py index af773278029..a45107181de 100644 --- a/homeassistant/components/python_script/__init__.py +++ b/homeassistant/components/python_script/__init__.py @@ -180,7 +180,7 @@ def guarded_import( # Allow import of _strptime needed by datetime.datetime.strptime if name == "_strptime": return __import__(name, globals, locals, fromlist, level) - raise ScriptError(f"Not allowed to import {name}") + raise ImportError(f"Not allowed to import {name}") def guarded_inplacevar(op: str, target: Any, operand: Any) -> Any: diff --git a/tests/components/python_script/test_init.py b/tests/components/python_script/test_init.py index 2d151b4b81e..14229e83662 100644 --- a/tests/components/python_script/test_init.py +++ b/tests/components/python_script/test_init.py @@ -711,4 +711,4 @@ async def test_no_other_imports_allowed( source = "import sys" hass.async_add_executor_job(execute, hass, "test.py", source, {}) await hass.async_block_till_done(wait_background_tasks=True) - assert "Error executing script: Not allowed to import sys" in caplog.text + assert "ImportError: Not allowed to import sys" in caplog.text