Skip to content
Latchkey

Python "yaml.scanner.ScannerError" in CI

PyYAML raises yaml.scanner.ScannerError when it cannot tokenize the document. The most common triggers are a literal tab used for indentation or an unquoted value containing a colon.

What this error means

A config-loading step fails with "yaml.scanner.ScannerError: while scanning ... mapping values are not allowed here" or "found character \t that cannot start any token".

python
yaml.scanner.ScannerError: mapping values are not allowed here
  in "config.yml", line 7, column 14

Common causes

Tabs used for indentation

YAML forbids tabs for indentation; a tab inserted by an editor breaks the scanner.

An unquoted value with a colon or special character

A bare value like url: http://x:8080 confuses the scanner; it must be quoted.

How to fix it

Fix indentation and quote ambiguous values

  1. Replace all tabs with spaces in the file.
  2. Quote any scalar that contains a colon, hash, or leading special character.
  3. Validate the file with a YAML linter in CI before the app reads it.
config.yml
# wrong: tab indent + unquoted colon value
# fixed:
endpoint: "http://service:8080"
timeout: 30

How to prevent it

  • Configure editors to expand tabs to spaces for YAML.
  • Run yamllint in CI before consuming config.
  • Use safe_load and surround risky scalars with quotes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →