Skip to content

Commit 07f7a98

Browse files
committed
Either use python3 or python to get remote encoding
1 parent eec71f4 commit 07f7a98

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

testinfra/backend/base.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,20 @@ def parse_containerspec(containerspec):
250250
user, name = name.split("@", 1)
251251
return name, user
252252

253-
def get_encoding(self):
254-
cmd = self.run("python -c 'import locale;print(locale.getpreferredencoding())'")
255-
if cmd.rc == 0:
256-
encoding = cmd.stdout_bytes.splitlines()[0].decode("ascii")
257-
else:
258-
# Python is not installed, we hope the encoding to be the same as
259-
# local machine...
253+
def get_encoding(self) -> str:
254+
encoding = None
255+
for python in ("python3", "python"):
256+
cmd = self.run(
257+
"%s -c 'import locale;print(locale.getpreferredencoding())'",
258+
python,
259+
encoding=None,
260+
)
261+
if cmd.rc == 0:
262+
encoding = cmd.stdout_bytes.splitlines()[0].decode("ascii")
263+
break
264+
# Python is not installed, we hope the encoding to be the same as
265+
# local machine...
266+
if not encoding:
260267
encoding = locale.getpreferredencoding()
261268
if encoding == "ANSI_X3.4-1968":
262269
# Workaround defaut encoding ascii without LANG set

0 commit comments

Comments
 (0)