【python】yaml.load 报错:TypeError: load() missing 1 required positional argument: ‘Loader‘

问题

使用 PyYaml 加载文件内容,我本机好的,其他同事执行代码出现了报错,错误如下:

yaml_content = yaml.load(stream)

E   TypeError: load() missing 1 required positional argument: 'Loader'

解决

由于 python load 存在一些安全问题,所以建议使用 safe_laod 来进行文件的加载。

yaml_content = yaml.safe_load(stream)

PyYAML 版本不同导致,更新代码后重新提交。
在这里插入图片描述

参考资料

问题说明

  • https://hackernoon.com/10-common-security-gotchas-in-python-and-how-to-avoid-them-e19fbe265e03(第 7 条)
  • https://talosintelligence.com/vulnerability_reports/TALOS-2017-0305
FullLoader
  • 版本说明:https://codebug.vip/questions-1685974.htm
  • 使用示例:http://www.xinbiancheng.cn/python3/python-method-yaml.FullLoader.html
终极答案
  • https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation#footnotes

猜你喜欢

转载自blog.csdn.net/lan_yangbi/article/details/121538961
今日推荐