diff --git a/homeassistant/components/microsoft/tts.py b/homeassistant/components/microsoft/tts.py index 38f46d886ded..9bcd7f533f8f 100644 --- a/homeassistant/components/microsoft/tts.py +++ b/homeassistant/components/microsoft/tts.py @@ -1,8 +1,8 @@ """Support for the Microsoft Cognitive Services text-to-speech service.""" -from http.client import HTTPException import logging from pycsspeechtts import pycsspeechtts +from requests.exceptions import HTTPError import voluptuous as vol from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider @@ -121,7 +121,7 @@ class MicrosoftProvider(Provider): contour=self._contour, text=message, ) - except HTTPException as ex: + except HTTPError as ex: _LOGGER.error("Error occurred for Microsoft TTS: %s", ex) return (None, None) return ("mp3", data) diff --git a/tests/components/microsoft/test_tts.py b/tests/components/microsoft/test_tts.py index f01eff556906..dd183ae7120e 100644 --- a/tests/components/microsoft/test_tts.py +++ b/tests/components/microsoft/test_tts.py @@ -3,7 +3,6 @@ from unittest.mock import patch from pycsspeechtts import pycsspeechtts import pytest -from requests import HTTPError from homeassistant.components import media_source, tts from homeassistant.components.media_player import ( @@ -14,7 +13,7 @@ from homeassistant.components.media_player import ( from homeassistant.components.microsoft.tts import SUPPORTED_LANGUAGES from homeassistant.config import async_process_ha_core_config from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ServiceNotFound +from homeassistant.exceptions import HomeAssistantError, ServiceNotFound from homeassistant.setup import async_setup_component from tests.common import async_mock_service @@ -314,7 +313,6 @@ async def test_service_say_error(hass: HomeAssistant, mock_tts, calls) -> None: ) assert len(calls) == 1 - # Note: the integration currently catches HTTPException instead of HTTPError. - with pytest.raises(HTTPError): + with pytest.raises(HomeAssistantError): await get_media_source_url(hass, calls[0].data[ATTR_MEDIA_CONTENT_ID]) assert len(mock_tts.mock_calls) == 2