此时安装的pyyaml版本为6.0.1,出现以下情况:
config = yaml.load(open(config_file).read())
TypeError: load() missing 1 required positional argument: 'Loader'
原因:
查询相关资料发现,yaml 5.1 版本后就舍弃了 yaml.load(file) 这个用法。
Yaml 5.1版本之后为使得load函数的安全性得以提高,就修改了需要指定Loader,通过默认加载器(FullLoader)禁止执行任意函数。
降低版本:y
(AAA) BBB@master:~$ pip install pyyaml==3.10
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pyyaml==3.10
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e4/a4/6c1f6c989d97c62ea50329b3803ca214ccfed7e4c1f82fe30c6e048645a0/PyYAML-3.10.zip (364 kB)
|████████████████████████████████| 364 kB 2.2 MB/s
Building wheels for collected packages: pyyaml
Building wheel for pyyaml (setup.py) ... done
Created wheel for pyyaml: filename=PyYAML-3.10-cp36-cp36m-linux_x86_64.whl size=42952 sha256=eecc0a866211c63c3607c0a53d7f7031a6394bef2c077e976d62f45d9652191f
Stored in directory: /home/jxm/.cache/pip/wheels/3f/1d/6f/27fb91b413ea55b0cdcd13b085e7d3801c6e984aed3a45ac1d
Successfully built pyyaml
Installing collected packages: pyyaml
Attempting uninstall: pyyaml
Found existing installation: PyYAML 6.0.1
Uninstalling PyYAML-6.0.1:
Successfully uninstalled PyYAML-6.0.1
Successfully installed pyyaml-3.10