Interview Prep/Python for DevOps/Data formats, HTTP & REST APIs

Why must you use `yaml.safe_load` rather than `yaml.load`?

BeginnerConceptData formats, HTTP & REST APIs
Answer

PyYAML's full loader can construct arbitrary Python objects from tags like !!python/object/apply:os.system, so loading an untrusted YAML file can execute code. yaml.safe_load only builds plain types (dict, list, str, int, float, bool, None, dates). Since PyYAML 5.1, calling yaml.load without a Loader warns, and 6.0 made the argument required. For writing, yaml.safe_dump(data, sort_keys=False).

All Python for DevOps questions Roadmap: Python for automation

More on Data formats, HTTP & REST APIs