diff --git a/.all-contributorsrc b/.all-contributorsrc index bc949e4..a684610 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3,9 +3,7 @@ "projectOwner": "chemelli74", "repoType": "github", "repoHost": "https://github.com", - "files": [ - "README.md" - ], + "files": ["README.md"], "imageSize": 80, "commit": true, "commitConvention": "angular", diff --git a/src/aiovodafone/api.py b/src/aiovodafone/api.py index 09c962c..0376005 100644 --- a/src/aiovodafone/api.py +++ b/src/aiovodafone/api.py @@ -83,9 +83,10 @@ async def _find_login_url(self) -> str: reply_text = await reply.text() soup = bs4.BeautifulSoup(reply_text, "html.parser") meta_refresh = soup.find("meta", {"http-equiv": "Refresh"}) - if meta_refresh is not None: - meta_content = meta_refresh["content"] - reply_url = urllib.parse.parse_qs(meta_content, separator="; ")["URL"][0] + if isinstance(meta_refresh, bs4.Tag) and "content" in meta_refresh: + meta_content = meta_refresh.get("content") + parsed_qs = urllib.parse.parse_qs(str(meta_content), separator="; ") + reply_url: str = parsed_qs["URL"][0] redirect_url = urllib.parse.urlparse(reply_url) if redirect_url.scheme != self.protocol: self.protocol = redirect_url.scheme @@ -101,7 +102,7 @@ async def _get_csrf_token(self, reply_text: str) -> None: soup = bs4.BeautifulSoup(reply_text, "html.parser") script_tag = soup.find("script", string=True) try: - token = re.findall("(?<=csrf_token)|[^']+", script_tag.string)[1] + token = re.findall("(?<=csrf_token)|[^']+", str(script_tag))[1] except IndexError: raise ModelNotSupported if not token: @@ -141,11 +142,11 @@ async def _reset(self) -> bool: """Reset page content before loading.""" payload = {"chk_sys_busy": ""} - reply: aiohttp.ClientResponse = await self._post_page_result( - "/data/reset.json", payload, True - ) + reply = await self._post_page_result("/data/reset.json", payload, True) + if isinstance(reply, aiohttp.ClientResponse): + return reply.status == 200 - return reply.status == 200 + return False async def _login_json(self, username: str, password: str) -> bool: """Login via json page""" diff --git a/tests/test_init.py b/tests/test_init.py index ba1f9bc..41e700d 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -9,10 +9,10 @@ def test_objects_can_be_imported(): - assert VodafoneStationDevice - assert VodafoneStationApi - assert VodafoneError - assert AlreadyLogged - assert CannotConnect - assert CannotAuthenticate - assert ModelNotSupported + assert type(VodafoneStationDevice) + assert type(VodafoneStationApi) + assert type(VodafoneError) + assert type(AlreadyLogged) + assert type(CannotConnect) + assert type(CannotAuthenticate) + assert type(ModelNotSupported)