Skip to content

Commit 6ec0af5

Browse files
committed
Handle IO encoding
1 parent 7e93102 commit 6ec0af5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/pip/_internal/network/auth.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ def get_credential(
5151
cls, service_name: str, username: Optional[str]
5252
) -> Optional[KeyRingCredential]:
5353
cmd = ["keyring", "get", service_name, str(username)]
54-
res = subprocess.run(cmd, capture_output=True)
54+
res = subprocess.run(
55+
cmd, capture_output=True, env=dict(PYTHONIOENCODING="utf-8")
56+
)
5557
if res.returncode:
5658
return None
57-
password = res.stdout.decode().strip("\n")
59+
password = res.stdout.decode("utf-8").strip("\n")
5860
return KeyRingCredential(username=username, password=password)
5961

6062
@classmethod
6163
def set_password(cls, service_name: str, username: str, password: str) -> None:
6264
cmd = ["keyring", "set", service_name, username]
63-
input_ = password.encode() + b"\n"
64-
res = subprocess.run(cmd, input=input_)
65+
input_ = password.encode("utf-8") + b"\n"
66+
res = subprocess.run(cmd, input=input_, env=dict(PYTHONIOENCODING="utf-8"))
6567
res.check_returncode()
6668
return None
6769

0 commit comments

Comments
 (0)