LoginSignup
28
15

More than 3 years have passed since last update.

PyYAMLがyaml.loadでYAMLLoadWarningを出してくるようになった件

Posted at

今日何気なくPyYAMLを使おうとしたら、yaml.load(f)のようなコードが軒並みYAMLLoadWarningを吐くようになった件。

file.py:***: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.

まあ、内容としては書いてあるとおりなのですが・・・。

PyYAML5.1以降、Loader引数無しでyaml.load()を呼ぶのは、エクスプロイトを仕込めてしまう危険があるのでダメになったそうな。なので、こうしなきゃいけなくなりました。

  yaml.load(f, Loader=yaml.SafeLoader)

yaml.safe_load()メソッドあたりを使ってもいいよとのこと。

警告に書かれたURLのページに書いてあるとおりですね。

28
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
15