mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 10:28:01 +00:00
Fix httpclient exceptions on read and improve error info (#655)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Module for HttpClientSession class."""
|
||||
import asyncio
|
||||
from typing import Any, Dict, Optional, Tuple, Union
|
||||
|
||||
import aiohttp
|
||||
@@ -58,25 +59,27 @@ class HttpClient:
|
||||
cookies=cookies_dict,
|
||||
headers=headers,
|
||||
)
|
||||
async with resp:
|
||||
if resp.status == 200:
|
||||
response_data = await resp.read()
|
||||
if json:
|
||||
response_data = json_loads(response_data.decode())
|
||||
|
||||
except (aiohttp.ServerDisconnectedError, aiohttp.ClientOSError) as ex:
|
||||
raise ConnectionException(
|
||||
f"Unable to connect to the device: {self._config.host}: {ex}"
|
||||
f"Unable to connect to the device: {self._config.host}: {ex}", ex
|
||||
) from ex
|
||||
except aiohttp.ServerTimeoutError as ex:
|
||||
except (aiohttp.ServerTimeoutError, asyncio.TimeoutError) as ex:
|
||||
raise TimeoutException(
|
||||
"Unable to query the device, " + f"timed out: {self._config.host}: {ex}"
|
||||
"Unable to query the device, "
|
||||
+ f"timed out: {self._config.host}: {ex}",
|
||||
ex,
|
||||
) from ex
|
||||
except Exception as ex:
|
||||
raise SmartDeviceException(
|
||||
f"Unable to query the device: {self._config.host}: {ex}"
|
||||
f"Unable to query the device: {self._config.host}: {ex}", ex
|
||||
) from ex
|
||||
|
||||
async with resp:
|
||||
if resp.status == 200:
|
||||
response_data = await resp.read()
|
||||
if json:
|
||||
response_data = json_loads(response_data.decode())
|
||||
|
||||
return resp.status, response_data
|
||||
|
||||
def get_cookie(self, cookie_name: str) -> Optional[str]:
|
||||
|
Reference in New Issue
Block a user