From 33454f68b8df14aceb88e89672f04a726725215b Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Wed, 12 Apr 2023 02:09:41 +0200 Subject: [PATCH] Encode username/password --- pyhon/connection/auth.py | 5 +++-- pyhon/connection/handler.py | 7 +++++-- setup.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pyhon/connection/auth.py b/pyhon/connection/auth.py index 5ba1cdd..603eeb7 100644 --- a/pyhon/connection/auth.py +++ b/pyhon/connection/auth.py @@ -5,6 +5,7 @@ import secrets import urllib from pprint import pformat from urllib import parse +from urllib.parse import quote from yarl import URL @@ -113,8 +114,8 @@ class HonAuth: "descriptor": "apex://LightningLoginCustomController/ACTION$login", "callingDescriptor": "markup://c:loginForm", "params": { - "username": self._email, - "password": self._password, + "username": quote(self._email), + "password": quote(self._password), "startUrl": parse.unquote( login_url.split("startURL=")[-1] ).split("%3D")[0], diff --git a/pyhon/connection/handler.py b/pyhon/connection/handler.py index d3c6e63..0d819e5 100644 --- a/pyhon/connection/handler.py +++ b/pyhon/connection/handler.py @@ -13,17 +13,19 @@ class HonBaseConnectionHandler: _HEADERS = {"user-agent": const.USER_AGENT, "Content-Type": "application/json"} def __init__(self, session=None): + self._create_session = session is None self._session = session 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): + if self._create_session: + self._session = aiohttp.ClientSession() return self @asynccontextmanager @@ -41,7 +43,8 @@ class HonBaseConnectionHandler: yield response async def close(self): - await self._session.close() + if self._create_session: + await self._session.close() class HonConnectionHandler(HonBaseConnectionHandler): diff --git a/setup.py b/setup.py index 3784e51..d4711aa 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.7.1", + version="0.7.2", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,