PyYAML requires Loader to be specified #5554

Closed
opened 2025-12-29 19:29:22 +01:00 by adam · 3 comments
Owner

Originally created by @hagbarddenstore on GitHub (Oct 25, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.8

Python version

3.9

Steps to Reproduce

  1. Run any script that calls load_yaml

Expected Behavior

The script should run without raising exceptions.

Observed Behavior

The script raises the following exception:

Traceback (most recent call last):
  File "/opt/netbox/netbox-0266ed5ce49534a388966caff5a7c0a2a47f23bd/netbox/extras/scripts.py", line 425, in _run_script
    script.output = script.run(data=data, commit=commit)
  File "/opt/netbox/netbox-0266ed5ce49534a388966caff5a7c0a2a47f23bd/netbox/scripts/my_script.py", line 145, in run
    config = self.load_yaml('my_script.yml')
  File "/opt/netbox/netbox-0266ed5ce49534a388966caff5a7c0a2a47f23bd/netbox/extras/scripts.py", line 350, in load_yaml
    data = yaml.load(datafile)
TypeError: load() missing 1 required positional argument: 'Loader'
Originally created by @hagbarddenstore on GitHub (Oct 25, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.8 ### Python version 3.9 ### Steps to Reproduce 1. Run any script that calls load_yaml ### Expected Behavior The script should run without raising exceptions. ### Observed Behavior The script raises the following exception: ``` Traceback (most recent call last): File "/opt/netbox/netbox-0266ed5ce49534a388966caff5a7c0a2a47f23bd/netbox/extras/scripts.py", line 425, in _run_script script.output = script.run(data=data, commit=commit) File "/opt/netbox/netbox-0266ed5ce49534a388966caff5a7c0a2a47f23bd/netbox/scripts/my_script.py", line 145, in run config = self.load_yaml('my_script.yml') File "/opt/netbox/netbox-0266ed5ce49534a388966caff5a7c0a2a47f23bd/netbox/extras/scripts.py", line 350, in load_yaml data = yaml.load(datafile) TypeError: load() missing 1 required positional argument: 'Loader' ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:29:22 +01:00
adam closed this issue 2025-12-29 19:29:22 +01:00
Author
Owner

@hagbarddenstore commented on GitHub (Oct 25, 2021):

Version 6.0 of PyYAML now requires that Loader be specified.

See this: c2743653bc (diff-642dbe3636af0ba5a6a20f0c346eeef2304a98ec91a7f609f6b29894a77127a8L103)

@hagbarddenstore commented on GitHub (Oct 25, 2021): Version 6.0 of PyYAML now requires that Loader be specified. See this: https://github.com/yaml/pyyaml/commit/c2743653bc89e42679ba097b4f9888db47c61d63#diff-642dbe3636af0ba5a6a20f0c346eeef2304a98ec91a7f609f6b29894a77127a8L103
Author
Owner

@hagbarddenstore commented on GitHub (Oct 25, 2021):

A workaround is to add the following at the top of netbox/extras/scripts.py:

try:
    from yaml import CLoader as Loader
except ImportError:
    from yaml import Loader

Then modify load_yaml to this:

def load_yaml(self, filename):
    """
    Return data from a YAML file
    """
    file_path = os.path.join(settings.SCRIPTS_ROOT, filename)
    with open(file_path, 'r') as datafile:
        data = yaml.load(datafile, Loader=Loader)

    return data
@hagbarddenstore commented on GitHub (Oct 25, 2021): A workaround is to add the following at the top of `netbox/extras/scripts.py`: ```python try: from yaml import CLoader as Loader except ImportError: from yaml import Loader ``` Then modify `load_yaml` to this: ```python def load_yaml(self, filename): """ Return data from a YAML file """ file_path = os.path.join(settings.SCRIPTS_ROOT, filename) with open(file_path, 'r') as datafile: data = yaml.load(datafile, Loader=Loader) return data ```
Author
Owner

@jeremystretch commented on GitHub (Oct 25, 2021):

Thanks @hagbarddenstore, not sure how I missed that in the package's release notes. 😞

* https://github.com/yaml/pyyaml/pull/561 -- always require `Loader` arg to `yaml.load()`

Also, we need to add a test for this.

@jeremystretch commented on GitHub (Oct 25, 2021): Thanks @hagbarddenstore, not sure how I missed that in the package's release notes. :disappointed: ``` * https://github.com/yaml/pyyaml/pull/561 -- always require `Loader` arg to `yaml.load()` ``` Also, we need to add a test for this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5554