ConstructorError - could not determine a constructor for custom tag (5.1)
See original GitHub issueThe 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:
- Created 5 years ago
- Reactions:4
- Comments:28 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try
I’m not sure though if this is intentional. Will have a closer look later.
None of the workarounds above worked for me, I had to use this loader:
Loader=yaml.BaseLoader
onPython 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)