From 6b2c60d5524903f6ddbc72dd71191b805c4b4f6f Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Wed, 12 Apr 2023 01:07:03 +0200 Subject: [PATCH] Fix session issues --- pyhon/connection/auth.py | 4 +++- pyhon/connection/handler.py | 6 ++++-- setup.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyhon/connection/auth.py b/pyhon/connection/auth.py index 6f587a2..5ba1cdd 100644 --- a/pyhon/connection/auth.py +++ b/pyhon/connection/auth.py @@ -86,7 +86,9 @@ class HonAuth: ): await self._error_logger(redirect2) return False - async with self._session.get(URL(url, encoded=True)) as login_screen: + async with self._session.get( + URL(url, encoded=True), headers={"user-agent": const.USER_AGENT} + ) as login_screen: self._called_urls.append( (login_screen.status, login_screen.request_info.url) ) diff --git a/pyhon/connection/handler.py b/pyhon/connection/handler.py index dc18082..d3c6e63 100644 --- a/pyhon/connection/handler.py +++ b/pyhon/connection/handler.py @@ -17,13 +17,13 @@ class HonBaseConnectionHandler: self._auth = None async def __aenter__(self): + self._session = aiohttp.ClientSession() return await self.create() async def __aexit__(self, exc_type, exc_val, exc_tb): await self.close() async def create(self): - self._session = aiohttp.ClientSession(headers=self._HEADERS) return self @asynccontextmanager @@ -75,7 +75,7 @@ class HonConnectionHandler(HonBaseConnectionHandler): self._request_headers["id-token"] = self._auth.id_token else: raise HonAuthenticationError("Can't login") - return headers | self._request_headers + return self._HEADERS | headers | self._request_headers @asynccontextmanager async def _intercept(self, method, *args, loop=0, **kwargs): @@ -95,6 +95,8 @@ class HonConnectionHandler(HonBaseConnectionHandler): response.status, await response.text(), ) + self._request_headers = {} + self._session.cookie_jar.clear_domain(const.AUTH_API.split("/")[-2]) await self.create() async with self._intercept( method, *args, loop=loop + 1, **kwargs diff --git a/setup.py b/setup.py index 71fb903..3784e51 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.7.0", + version="0.7.1", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,