add-apt-repository 抛出 Python 错误:UnicodeDecodeError: 'ascii' 编解码器无法解码字节 0xc5

add-apt-repository 抛出 Python 错误:UnicodeDecodeError: 'ascii' 编解码器无法解码字节 0xc5

尝试安装最新的 PHP5 软件包,因此我添加了我需要的 repo(sudo add-apt-repository ppa:ondrej/php5),结果如下:

    Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 141, in run
    self.add_ppa_signing_key(self.ppa_path)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 234, in add_ppa_signing_key
    tmp_export_keyring, signing_key_fingerprint, tmp_keyring_dir):
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 186, in _verify_fingerprint
    got_fingerprints = self._get_fingerprints(keyring, keyring_dir)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 178, in _get_fingerprints
    output = subprocess.check_output(cmd, universal_newlines=True)
  File "/usr/lib/python3.2/subprocess.py", line 516, in check_output
    output, unused_err = process.communicate()
  File "/usr/lib/python3.2/subprocess.py", line 811, in communicate
    stdout = _eintr_retry_call(self.stdout.read)
  File "/usr/lib/python3.2/subprocess.py", line 456, in _eintr_retry_call
    return func(*args)
  File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 92: ordinal not in range(128)

在 Ubuntu 12.04 服务器上运行

答案1

software-properties-common 有缺陷,因此如果有时间,请将其报告为 software-properties-common 中的缺陷。

有人指出了更好的解决方法问题追踪器添加存储库时使用特定的 Unicode 语言环境

LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php5-5.6

答案2

尝试安装语言包,这可能会纠正你的编码问题,例如

sudo apt-get install language-pack-en

这将为所有受支持的软件包(包括 Python)提供英语翻译数据更新。

看:UnicodeEncodeError:'ascii'编解码器无法编码字符

否则,请手动设置区域设置,例如

$ locale -a | grep "^en_.\+UTF-8"
en_GB.UTF-8
en_US.UTF-8
$ export LC_ALL=en_GB.UTF-8
$ export LANG=en_GB.UTF-8

有关的:apt-get install 时出现语言环境错误

答案3

如果你在docker中,这对我有用:

RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php

之后:

RUN apt-get update
RUN apt-get install -y php7.2

答案4

对于我来说,在 php 之前添加 php5-compat 解决了我在 ubuntu 16 上的问题。

sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php5-compat

进而

sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php

相关内容