关于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 就行了 不过还有更多用法 看下面

在这里插入图片描述
详细的可以自己去他的GitHub上去看 https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation#footnotes

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

  • 23
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值