diff --git a/typer/_completion_shared.py b/typer/_completion_shared.py index 10de54420d..0f52f6a82c 100644 --- a/typer/_completion_shared.py +++ b/typer/_completion_shared.py @@ -183,15 +183,15 @@ def install_powershell(*, prog_name: str, complete_var: str, shell: str) -> Path if isinstance(result.stdout, str): # pragma: no cover path_str = result.stdout if isinstance(result.stdout, bytes): - try: - # PowerShell would be predominant in Windows - path_str = result.stdout.decode("windows-1252") - except UnicodeDecodeError: # pragma: no cover + for encoding in ["windows-1252", "utf8", "cp850"]: try: - path_str = result.stdout.decode("utf8") - except UnicodeDecodeError: - click.echo("Couldn't decode the path automatically", err=True) - raise + path_str = result.stdout.decode(encoding) + break + except UnicodeDecodeError: # pragma: no cover + pass + if not path_str: # pragma: no cover + click.echo("Couldn't decode the path automatically", err=True) + raise click.exceptions.Exit(1) path_obj = Path(path_str.strip()) parent_dir: Path = path_obj.parent parent_dir.mkdir(parents=True, exist_ok=True)