question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConstructorError - could not determine a constructor for custom tag (5.1)

See original GitHub issue

The following code was working on 3.13 but no longer works in 5.1:

import yaml

class Ref(yaml.YAMLObject):
    yaml_tag = '!Ref'
    def __init__(self, val):
        self.val = val

    @classmethod
    def from_yaml(cls, loader, node):
        return cls(node.value)

yaml.load('Foo: !Ref bar')

I get the following exception on 5.1:

yaml.constructor.ConstructorError: could not determine a constructor for the tag '!Ref'
  in "<unicode string>", line 1, column 6:
    Foo: !Ref bar

This is true whether I use yaml.load, yaml.full_load or yaml.unsafe_load.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:28 (11 by maintainers)

github_iconTop GitHub Comments

66reactions
perlpunkcommented, Mar 14, 2019

Try

yaml.load('Foo: !Ref bar', Loader=yaml.Loader)

I’m not sure though if this is intentional. Will have a closer look later.

27reactions
rmaroucommented, Nov 28, 2019

None of the workarounds above worked for me, I had to use this loader: Loader=yaml.BaseLoader on Python 3.7.0 PyYaml==5.1.2 or == 5.2b1

(edited) I reproduced using the same code: yaml.load('Foo: !Ref bar') This worked for me :yaml.load('Foo: !Ref bar', Loader=yaml.BaseLoader)

Read more comments on GitHub >

github_iconTop Results From Across the Web

YAML Error: could not determine a constructor for the tag
I'm using Ruamel's library and YamlReader to glue a bunch of CloudFormation pieces together into a single, merged template. Is bang-notation ...
Read more >
yaml: could not determine a constructor for the tag
First, a bit of background. The errors above both mean that the loader encountered an explicit tag, but doesn't know how to construct...
Read more >
PyYAML Documentation
Constructors, representers, resolvers. You may define your own application-specific tags. The easiest way to do it is to define a subclass of yaml.YAMLObject...
Read more >
YAML Deserialization Attack in Python - Net Square
Serialize a sequence of Python objects into a YAML stream. Produce only basic YAML tags. No python class objects will be serialized if...
Read more >
Chapter 5: Custom tag workers and CSS appliers
html HTML file), but we'll change the tag worker factory in such a way that the <a> -tag is treated as a <span>...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found