diff --git a/pyhtcc/pyhtcc.py b/pyhtcc/pyhtcc.py index ce29904..94ed8b6 100644 --- a/pyhtcc/pyhtcc.py +++ b/pyhtcc/pyhtcc.py @@ -524,7 +524,12 @@ def _do_authenticate(self) -> None: Can raise various exceptions. Users are expected to use authenticate() instead of this method. """ self.session = requests.session() - self.session.auth = (self.username, self.password) + + # See https://github.com/psf/requests/issues/4564 for why we encode user/pass to bytes + self.session.auth = ( + self.username.encode("utf-8"), + self.password.encode("utf-8"), + ) logger.debug(f"Attempting authentication for {self.username}") diff --git a/tests/test_pyhtcc.py b/tests/test_pyhtcc.py index 20387dd..cbf1a44 100644 --- a/tests/test_pyhtcc.py +++ b/tests/test_pyhtcc.py @@ -570,3 +570,6 @@ def test_logout_failure_error(self): self.pyhtcc.logout() assert str(err.value) == "Unable to logout user: user, status=500" + + def test_auth_gets_set_to_utf8_bytes(self): + assert self.mock_session.auth == (b"user", b"pass")