mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-12-22 18:55:32 +00:00
Fix session issues
This commit is contained in:
parent
46e6a85e84
commit
6b2c60d552
|
@ -86,7 +86,9 @@ class HonAuth:
|
||||||
):
|
):
|
||||||
await self._error_logger(redirect2)
|
await self._error_logger(redirect2)
|
||||||
return False
|
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(
|
self._called_urls.append(
|
||||||
(login_screen.status, login_screen.request_info.url)
|
(login_screen.status, login_screen.request_info.url)
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,13 +17,13 @@ class HonBaseConnectionHandler:
|
||||||
self._auth = None
|
self._auth = None
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
|
self._session = aiohttp.ClientSession()
|
||||||
return await self.create()
|
return await self.create()
|
||||||
|
|
||||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||||
await self.close()
|
await self.close()
|
||||||
|
|
||||||
async def create(self):
|
async def create(self):
|
||||||
self._session = aiohttp.ClientSession(headers=self._HEADERS)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
|
@ -75,7 +75,7 @@ class HonConnectionHandler(HonBaseConnectionHandler):
|
||||||
self._request_headers["id-token"] = self._auth.id_token
|
self._request_headers["id-token"] = self._auth.id_token
|
||||||
else:
|
else:
|
||||||
raise HonAuthenticationError("Can't login")
|
raise HonAuthenticationError("Can't login")
|
||||||
return headers | self._request_headers
|
return self._HEADERS | headers | self._request_headers
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def _intercept(self, method, *args, loop=0, **kwargs):
|
async def _intercept(self, method, *args, loop=0, **kwargs):
|
||||||
|
@ -95,6 +95,8 @@ class HonConnectionHandler(HonBaseConnectionHandler):
|
||||||
response.status,
|
response.status,
|
||||||
await response.text(),
|
await response.text(),
|
||||||
)
|
)
|
||||||
|
self._request_headers = {}
|
||||||
|
self._session.cookie_jar.clear_domain(const.AUTH_API.split("/")[-2])
|
||||||
await self.create()
|
await self.create()
|
||||||
async with self._intercept(
|
async with self._intercept(
|
||||||
method, *args, loop=loop + 1, **kwargs
|
method, *args, loop=loop + 1, **kwargs
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open("README.md", "r") as f:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.7.0",
|
version="0.7.1",
|
||||||
author="Andre Basche",
|
author="Andre Basche",
|
||||||
description="Control hOn devices with python",
|
description="Control hOn devices with python",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
|
Loading…
Reference in a new issue