Fix session issues

This commit is contained in:
Andre Basche 2023-04-12 01:07:03 +02:00
parent 46e6a85e84
commit 6b2c60d552
3 changed files with 8 additions and 4 deletions

View file

@ -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)
)

View file

@ -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

View file

@ -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,