Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(charset issue): Resolution for issue 6102 #6426

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion requests/auth.py
Expand Up @@ -122,6 +122,19 @@ def init_per_thread_state(self):
self._thread_local.chal = {}
self._thread_local.pos = None
self._thread_local.num_401_calls = None

@staticmethod
def encode_to_bytes(data, encoding="latin-1"):
"""
This function encodes input data to bytes using the specified
encoding (default is Latin-1). It returns the encoded data as bytes.

:rtype: bytes
"""
if type(data) == bytes:
return data
str_data = str(data)
return str_data.encode(encoding)

def build_digest_header(self, method, url):
"""
Expand Down Expand Up @@ -186,7 +199,11 @@ def sha512_utf8(x):
if p_parsed.query:
path += f"?{p_parsed.query}"

A1 = f"{self.username}:{realm}:{self.password}"
username = self.encode_to_bytes(self.username)
realm = self.encode_to_bytes(realm)
password = self.encode_to_bytes(self.password)

A1 = b"%s:%s:%s" % (username, realm, password)
A2 = f"{method}:{path}"

HA1 = hash_utf8(A1)
Expand Down