131

I want to upload an app to Google App Engine:

I get this

Error parsing yaml file:
mapping values are not allowed here
  in "/home/antonio/Desktop/ATI/climate-change/app.yaml", line 2, column 8 

When running

./appcfg.py update /home/antonio/Desktop/ATI/climate-change

with this app.yaml file:

application:climate-change
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: helloworld.app

line 2, column 8 corresponds to the version line. What is wrong here? Btw, I'm using Ubuntu 12.04 here.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
andandandand
  • 21,946
  • 60
  • 170
  • 271
  • 1
    Make sure you are not copying the text from Skype or some software. Paste the text first into a text editor, then copy from there. I copied from Skype and visibly there were no problems. I solved it by simply deleting and then retyping 'space' to create valid (Unix) spaces. – Nadjib Mami Oct 19 '20 at 14:30

11 Answers11

151

Change

application:climate-change

to

application: climate-change

The space after the colon is mandatory in yaml if you want a key-value pair. (See http://www.yaml.org/spec/1.2/spec.html#id2759963)

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
88

Another cause is wrong indentation which means trying to create the wrong objects. I've just fixed one in a Kubernetes Ingress definition:

Wrong

- path: / 
    backend: 
      serviceName: <service_name> 
      servicePort: <port> 

Correct

- path: /
  backend:
    serviceName: <service_name>
    servicePort: <port>
lcfd
  • 1,326
  • 10
  • 12
  • 5
    Yep, this was my problem too. This is why python is frakking stupid. Whitespace should NOT be important. – Kenny Wyland Mar 10 '17 at 00:23
  • Had no idea this was a python file. I had ONE extra space. Crazy. Thank you for the answer! – Vern Jensen Jul 07 '17 at 00:22
  • 9
    It's NOT a Python file. YAML and Python are similar in that they both use "load-bearing whitespace" to reduce the amount of punctuation you would otherwise need. – shacker Apr 07 '18 at 00:12
  • 3
    @shacker I'd rather have punctuation. – mal Jun 26 '19 at 08:03
  • Yeah. But somehow the indentation in python never gave me as much issues as in YAML. The object in a list item spacing gets me every time. YAML really is a horrible format. Why can't we just have JSON with comments and trailing commas. Would be so much easier. – Gellweiler Feb 01 '20 at 16:42
  • 3
    @mal The good news is that yaml is a superset of json.. So, `[{"path": "/", "backend": {"serviceName": "", "servicePort": ""}}]` is valid yaml also :) – iCodeSometime Jan 05 '22 at 17:29
6

Or, if spacing is not the problem, it might want the parent directory name rather than the file name.

Not $ dev_appserver helloapp.py
But $ dev_appserver hello/

For example:

Johns-Mac:hello john$ dev_appserver.py helloworld.py
Traceback (most recent call last):
  File "/usr/local/bin/dev_appserver.py", line 82, in <module>
    _run_file(__file__, globals())
...
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/yaml_listener.py", line 212, in _GenerateEventParameters
    raise yaml_errors.EventListenerYAMLError(e)
google.appengine.api.yaml_errors.EventListenerYAMLError: mapping values are not allowed here
  in "helloworld.py", line 3, column 39

Versus

Johns-Mac:hello john$ cd ..
Johns-Mac:fbm john$ dev_appserver.py hello/
INFO     2014-09-15 11:44:27,828 api_server.py:171] Starting API server at: http://localhost:61049
INFO     2014-09-15 11:44:27,831 dispatcher.py:183] Starting module "default" running at: http://localhost:8080
John Mee
  • 50,179
  • 34
  • 152
  • 186
6

I've seen this error in a similar situation to mentioned in Joe's answer:

description: Too high 5xx responses rate: {{ .Value }} > 0.05

We have a colon in description value. So, the problem is in missing quotes around description value. It can be resolved by adding quotes:

description: 'Too high 5xx responses rate: {{ .Value }} > 0.05'
Evgeny Veretennikov
  • 3,889
  • 2
  • 16
  • 36
5

Maybe this will help someone else, but I've seen this error when the RHS of the mapping contains a colon without enclosing quotes, such as:

someKey: another key: Change to make today: work out more

should be

someKey: another key: "Change to make today: work out more"

Joe
  • 1,014
  • 1
  • 13
  • 28
5

Incorrect:

people:
  empId: 123
  empName: John
    empDept: IT

Correct:

people:
  emp:
    id: 123
    name: John
    dept: IT
Saljack
  • 2,072
  • 21
  • 24
Sajeev
  • 51
  • 1
  • 1
2

There are couple of issues in the yaml file as mentioned by most, with yaml files normally it gets messy to identify the issue,

fortunately it can be identified easily with tools like yaml lint and you may not require help from the community.

Install it

npm install -g yaml-lint

Here is how you can validate

E:\githubRepos\prometheus-sql-exporter-usage>yamllint docker-compose.yaml
√ YAML Lint successful.
craftsmannadeem
  • 2,665
  • 26
  • 22
1

My issue was a missing set of quotes;

Foo: bar 'baz'

should be

Foo: "bar 'baz'"
Graham P Heath
  • 7,009
  • 3
  • 31
  • 45
1

In my case I had this error when I was writing yml for a bitbucket ci pipeline.

script:
  - curl https://url.com -H "Content-Type: application/json"

Although header comes wrapped in quotes, yml parser complains "mapping values are not allowed here" because there's the space after the colon.

The solution is to remove the space:

script:
  - curl https://url.com -H "Content-Type:application/json"
                                          ^
Artem S.
  • 543
  • 5
  • 16
0

In our case, we had weird dash () instead of normal one (-) due to copy and paste.

metasync
  • 338
  • 1
  • 10
0

There was C-styled comment on top:

// some comment
root:
  ...

And nobody noticed this on review :/

Simon Logic
  • 330
  • 4
  • 10