错误提示如下:

Traceback (most recent call last):
  File "certdata2pem.py", line 150, in <module>
    encoded = base64.b64encode(obj['CKA_VALUE']).decode()
  File "/usr/lib64/python2.6/base64.py", line 53, in b64encode
    encoded = binascii.b2a_base64(s)[:-1]
TypeError: b2a_base64() argument 1 must be string or read-only buffer, not bytearray
make[5]: *** [all] Error 1
make[5]: Leaving directory `/home/ /wr1200js/lede/build_dir/target-mipsel_24kc_musl/ca-certificates/mozilla'
make[4]: *** [all] Error 2
make[4]: Leaving directory `/home/ /wr1200js/lede/build_dir/target-mipsel_24kc_musl/ca-certificates'
make[3]: *** [/home/ /wr1200js/lede/build_dir/target-mipsel_24kc_musl/ca-certificates/.built] Error 2
make[3]: Leaving directory `/home/ /wr1200js/lede/package/system/ca-certificates'
time: package/system/ca-certificates/compile#0.99#0.20#1.21
make[2]: *** [package/system/ca-certificates/compile] Error 2
make[2]: Leaving directory `/home/ /wr1200js/lede'
make[1]: *** [/home/ /wr1200js/lede/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile] Error 2
make[1]: Leaving directory `/home/ /wr1200js/lede'
make: *** [world] Error 2

于是进入lede/build_dir/target-mipsel_24kc_musl/ca-certificates/mozilla查看certdata2pem.py文件内容
发现该文件的逻辑为读入certdata.txt文件内的内容,结合blacklist.txt文件,批量生成证书文件。
按照错误提示的第150行,发现将读入的证书数据编码时出现问题,故print之,发现乱码。
注意到第40行用可疑的for line in io.open('certdata.txt', 'rt', encoding='utf8'):写死了编码格式为utf8
使用file命令查看file certdata.txt
得到:certdata.txt: ASCII English text
iconv -f ASCII -t UTF-8 -c certdata.txt -o certdata.txt
转码后仍旧报错,开始考虑是否为python版本问题。
遂执行

yum -y install centos-release-scl
yum -y install rh-python36
scl enable rh-python36 bash

问题得到顺利解决
关于scl的用法,可查看这篇文章

Last modification:February 12th, 2020 at 11:18 pm