如何修复Yaml文件中的“在这种情况下不允许映射值”错误?

时间:2019-06-15 16:09:59

标签: web-scraping yaml

我浏览了类似的问题,并相信我已经运用了我能够从答案中收集到的所有信息。

我有一个.yml文件,据我所知,每个元素的格式都相同。但是根据YamlLint.com

(<unknown>): mapping values are not allowed in this context at line 119 column 16

在这种情况下,第119行是下面包含第二个单词“ transitions”的行。我可以告诉每个元素相同的格式。我在这里想念什么吗?

  landingPage:
    include: false
    transitions:
      -
        condition:location
        nextState:location

  location:
    include:false
    transitions:
      -
        condition:excluded
        nextState:excluded

  excluded:
    include:false
    transitions:
      -
        condition:excluded
        nextState: excluded
      -
        condition:age
        nextState:age

4 个答案:

答案 0 :(得分:1)

您不能使用多行普通标量,例如include:false transitions是映射的关键,这就是为什么您会得到此上下文错误中不允许的映射值的原因。

您要么忘记必须在值指示符(:)后留一个空格,而您打算这样做:

        include: false
        transitions:

或者您需要引用多行标量:

        'include:false
        transitions':

或者您需要将该普通标量放在一行上:

        include:false transitions:

请注意,某些库根本不允许使用纯净标量的值指示符,即使它们后面没有空格

答案 1 :(得分:1)

我们需要在“:”之前使用空格 然后它将执行 检查下面的yaml脚本 http://www.yamllint.com/

答案 2 :(得分:0)

yaml 文件有几个问题,yaml 文件会变得很乱,幸运的是可以使用 yaml lint 之类的工具轻松识别

安装

npm install -g yaml-lint

以下是验证方法

E:\githubRepos\prometheus-sql-exporter-usage\etc>yamllint prometheus.yaml
√ YAML Lint successful.

答案 3 :(得分:0)

对我来说,问题是来自剪切和粘贴的 unicode '-'。视觉上看起来不错,但字符是“EN DASH”(U+2013)而不是“HYPHEN MINUS”(U+002D)

相关问题