Skip to content

Commit

Permalink
fix PyYAML warning on call of yaml.load(…)
Browse files Browse the repository at this point in the history
Since PyYAML v5.1 a warning on deprecation is printed:

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

Use the `FullLoader`s suggared variant `yaml.full_load` according to the
documentation [1] if it's present. Then it's assumed that PyYAML >= v5.1 is
used.

[1] https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation#how-to-disable-the-warning
  • Loading branch information
agebhar1 committed Jun 30, 2019
1 parent 4aa6fe9 commit f8751ca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hbmqtt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def read_yaml_config(config_file):
config = None
try:
with open(config_file, 'r') as stream:
config = yaml.load(stream)
config = yaml.full_load(stream) if hasattr(yaml, 'full_load') else yaml.load(stream)
except yaml.YAMLError as exc:
logger.error("Invalid config_file %s: %s" % (config_file, exc))
return config

0 comments on commit f8751ca

Please sign in to comment.