diff --git a/PFERD/ilias/authenticators.py b/PFERD/ilias/authenticators.py index 4e058d8..7701092 100644 --- a/PFERD/ilias/authenticators.py +++ b/PFERD/ilias/authenticators.py @@ -10,6 +10,7 @@ import bs4 import requests from ..authenticators import UserPassAuthenticator +from ..utils import soupify LOGGER = logging.getLogger(__name__) @@ -55,7 +56,7 @@ class KitShibbolethAuthenticator(IliasAuthenticator): "target": "/shib_login.php", "home_organization_selection": "Mit KIT-Account anmelden", } - soup = bs4.BeautifulSoup(sess.post(url, data=data)) + soup = soupify(sess.post(url, data=data)) # Attempt to login using credentials, if necessary while not self._login_successful(soup): @@ -73,7 +74,7 @@ class KitShibbolethAuthenticator(IliasAuthenticator): "j_username": self._auth.username, "j_password": self._auth.password, } - soup = bs4.BeautifulSoup(sess.post(url, data=data)) + soup = soupify(sess.post(url, data=data)) if not self._login_successful(soup): print("Incorrect credentials.") diff --git a/PFERD/utils.py b/PFERD/utils.py index 8233ad1..b29f8cb 100644 --- a/PFERD/utils.py +++ b/PFERD/utils.py @@ -6,6 +6,7 @@ import logging from pathlib import Path, PurePath from typing import Optional, Tuple +import bs4 import requests from colorama import Fore, Style @@ -30,6 +31,10 @@ def rename(path: PurePath, to_name: str) -> PurePath: return PurePath(*path.parts[:-1], to_name) +def soupify(response: requests.Response) -> bs4.BeautifulSoup: + return bs4.BeautifulSoup(response.text, "html.parser") + + def stream_to_path(response: requests.Response, to_path: Path, chunk_size: int = 1024 ** 2) -> None: """ Download a requests response content to a file by streaming it. This