Skip to content

Commit

Permalink
Fix #16. Pre-encode user/password as bytes to allow all of utf-8 to b…
Browse files Browse the repository at this point in the history
…e passed along

Works around psf/requests#4564
  • Loading branch information
csm10495 committed Apr 4, 2024
1 parent 94076ff commit d330b36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pyhtcc/pyhtcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
3 changes: 3 additions & 0 deletions tests/test_pyhtcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit d330b36

Please sign in to comment.