【问题标题】:<Psych::SyntaxError: did not find expected key while parsing a block mapping<Psych::SyntaxError: did not find expected key while parsing a block mapping
【发布时间】:2017-11-06 10:31:10
【问题描述】:

当我启动服务器时,我得到这个错误:

I18n::InvalidLocaleData
can not load translations from /Users/Apple/myapp-website-freelance/config/locales/fr.yml: #<Psych::SyntaxError: (/Users/Apple/myapp-website-freelance/config/locales/fr.yml): did not find expected key while parsing a block mapping at line 2 column 3>

虽然,yaml 文件在第 2 行第 3 列看起来很正常:

fr:
  Electronics_Circuits_Simulator_Realistic_Interface: "Simulateur de circuits electroniques. Interface reelle."

有什么想法吗?

【问题讨论】:

  • 在我的例子中是a: *default\n b: 1 代替了a:\n &lt;&lt;: *default\n b: 1

标签: ruby-on-rails-4 yaml


【解决方案1】:

这个错误通常会产生误导并指出错误的行

在整个 YML 文件中寻找多余的空格并尝试用“”替换所有封闭的单引号,它应该可以工作!

一个可能的原因是:

default: &default
  a: 1
production: *default
  b: 2

代替:

default: &default
  a: 1
production:
  <<: *default
  b: 2

【讨论】:

    【解决方案2】:

    如果您首先通过 ERB 解析 YAML,请检查您的最终 YAML 输出(例如环境变量的嵌入)以查看它们是否包含无效的 YAML,例如不完整的字符串等。

    【讨论】:

      【解决方案3】:

      在可能的情况下,password 字段可能缺少带有“!@#”等符号的配额。使用 yaml validator 检查您的 yaml 文件。

      【讨论】:

        【解决方案4】:

        我在行尾有一个逗号,来自其他地方的错误复制/粘贴。删除逗号将 YAML 文件恢复为正常使用(在本例中为我的 application.yml)。该错误显然涵盖了各种各样的 YAML 语法问题。我怀疑这意味着由于当前行的语法错误,YAML 解析器无法转到 YAML 文件中的下一行。

        【讨论】:

          【解决方案5】:

          我遇到了类似的问题,但在我的情况下,它不是@Dijiflex 的解决方案中显示的空格,而是如下例所示的撇号或单引号字符;

          pages:
              title: "I don't have time this evening"
          

          请注意不要这个词,所以我所做的就是将其转义如下

          pages:
              title: "I don\\'t have time this evening"
          

          我希望你现在有这个想法? 享受

          【讨论】:

            【解决方案6】:

            如果您正在处理许多项目,请确保您在网站部分的连字符 - 符合要求,请查看下面我有绿线的图片。

            【讨论】:

            • 感谢刚刚使用的图像,因为我需要画那条线
            【解决方案7】:

            检查 YML 文件中是否有任何多余的空格。另外,如果你和我一样,你可能会忘记在 YML 模板中删除 {}

            # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
            
            # This model initially had no columns defined. If you add columns to the
            # model remove the '{}' from the fixture names and add the columns immediately
            # below each fixture, per the syntax in the comments below
            #
            one: {}
            # column: value
            #
            two: {}
            # column: value
            

            【讨论】:

              猜你喜欢
              • 2022-12-28
              • 2022-11-20
              • 1970-01-01
              • 2023-03-25
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2022-12-05
              相关资源
              最近更新 更多