关于Yaml更新并弃用yaml.load()导致老代码报错 YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated

问题

重装了电脑后重新装了Yaml 然后老代码一运行就报错
YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
其实也不影响使用,当时就感觉很不爽,为了找原因我就去百度了一圈,并没有答案。

原因

然后我就直接去PyYAML的Github看了下,

This page explains the PyYAML 5.1 deprecation of the plain yaml.load(input) function. See Footnotes.
Use of PyYAML’s yaml.load function without specifying the Loader=… parameter, has been deprecated. In PyYAML version 5.1, you will get a warning, but the function will still work. See How to Disable the Warning below.
Before PyYAML 5.1, the PyYAML.load function could be easily exploited to call any Python function. That means it could call any system command using os.system(). Here is a trivial example:

反正就是5.1弃用了load原本的用法

解决

不用改很多代码 加一句就行了 在yaml.load(list, Loader=yaml.FullLoader) 加上 Loader=yaml.FullLoader 就行了 不过还有更多用法 看下面

关于Yaml更新并弃用yaml.load()导致老代码报错 YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated_第1张图片
详细的可以自己去他的GitHub上去看 https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation#footnotes

最后感谢评论区大佬指正我的拼写错误,抱歉给大家带坑里了

你可能感兴趣的:(python,yaml)