Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

python - ScannerError: mapping values are not allowed here in "config.yaml"?

I want to configure a yaml file for all project configuration, but this below file I am not able to read/parse it?

Here is the error I am getting, What am I doing wrong here?

ScannerError: mapping values are not allowed here
  in "config.yaml", line 7, column 13

appName: test
logLevel: WARN


TESTER:
    ENVIRONMENT: staging
      CONFIG:
        DATABASE:
          HOST: 2123.3123.2112.12
          USERNAME: x
          PASSWORD: y
          DB: Q
        CLASSIFIER:
          IMG_WIDTH: 380
          IMG_HEIGHT: 380
          HOST: 0.0.0.0:3201
question from:https://stackoverflow.com/questions/65936747/scannererror-mapping-values-are-not-allowed-here-in-config-yaml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Issue is with the indentation of your yaml. ENVIRONMENT is having different indent compared to CONFIG, which is in next line.

You can use any online validators like http://www.yamllint.com or https://codebeautify.org/yaml-validator to validate your yaml files.

This is valid YAML:

appName: test
logLevel: WARN


TESTER:
    ENVIRONMENT: staging
    CONFIG:
        DATABASE:
            HOST: 2123.3123.2112.12
            USERNAME: x
            PASSWORD: y
            DB: Q
        CLASSIFIER:
            IMG_WIDTH: 380
            IMG_HEIGHT: 380
            HOST: 0.0.0.0:3201

UPDATE:
If you want to use multiple configurations, then generally list of maps is used with a name attribute like below.
It is a good practice to give NAME attribute, even if there is only one config.

appName: test
logLevel: WARN

TESTER:
  - NAME: staging
    ENVIRONMENT: staging
    CONFIG:
      DATABASE:
        HOST: 2123.3123.2112.12
        USERNAME: x
        PASSWORD: 'y'
        DB: Q
      CLASSIFIER:
        IMG_WIDTH: 380
        IMG_HEIGHT: 380
        HOST: '0.0.0.0:3201'
  - NAME: production
    ENVIRONMENT: production
    CONFIG:
      DATABASE:
        HOST: 2123.3123.2112.14
        USERNAME: xP
        PASSWORD: yP
        DB: Q
      CLASSIFIER:
        IMG_WIDTH: 380
        IMG_HEIGHT: 380
        HOST: '0.0.0.0:3201'

In this YAML, he similarly uses two maps under deploy


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...