Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update(requests): fix merge conflict
  • Loading branch information
kalingth committed Jul 26, 2024
commit 1967fff7ed14a1761f388b7e037168a98e93625c
18 changes: 17 additions & 1 deletion src/requests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ def init_per_thread_state(self):
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):
"""
:rtype: str
Expand Down Expand Up @@ -186,7 +198,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 = f"{username}:{realm}:{password}"
A2 = f"{method}:{path}"

HA1 = hash_utf8(A1)
Expand Down