Skip to content

configparser throws ParsingError when reading ini file #134516

Not planned
@PhilippKosarev

Description

@PhilippKosarev

Bug report

Bug description:

Code snippet:

parser = configparser.ConfigParser()
ini_file = '/home/philipp/.local/share/Steam/steamapps/compatdata/244210/pfx/drive_c/users/steamuser/Documents/Assetto Corsa/cfg/extension/state/lua/app/CspDebug.ini'
parser.read(ini_file)

Error:

File "/mnt/sda1/Programming/accm/libjam/notebook.py", line 58, in read_ini
    parser.read(ini_file)
    ~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib64/python3.13/configparser.py", line 735, in read
    self._read(fp, filename)
    ~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/configparser.py", line 1050, in _read
    ParsingError._raise_all(self._read_inner(fp, fpname))
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/configparser.py", line 334, in _raise_all
    raise next(exceptions).combine(exceptions)
configparser.ParsingError: Source contains parsing errors: '/home/philipp/.local/share/Steam/steamapps/compatdata/244210/pfx/drive_c/users/steamuser/Documents/Assetto Corsa/cfg/extension/state/lua/app/CspDebug.ini'
	[line  9]: "}'\n"

Contents of ini_file:

[STRING]
12866846752895976527='{
  distance = 100,
  count = 10,
  dirty = false,
  flags = { bsphere = false, bbox = true, outline = true, text = true },
  filter = "?",
  active = false
}'

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Activity

Zheaoli

Zheaoli commented on May 22, 2025

@Zheaoli
Contributor

I think this is not a bug, This is not a regular ini config file.

Actually, we don't have a RFC for ini config file. So the behavior will depend on the developer. On my test, the developer don't support this grammar in the ini parse lib in other programming like Go, Java at the same time.

cc @picnixz

picnixz

picnixz commented on May 23, 2025

@picnixz
Member

The problem is the handling of multiline values. Multiline values are handled according to their indentation, namely:

[STRING]
12866846752895976527='{
  distance = 100,
  count = 10,
  dirty = false,
  flags = { bsphere = false, bbox = true, outline = true, text = true },
  filter = "?",
  active = false
}'

is actually equivalent to declare a field 12866846752895976527 which expands until active = False and then a new field }' which in this case has no value, so is not a valid key.

The solution, I think, would be the following:

[STRING]
12866846752895976527='{
  distance = 100,
  count = 10,
  dirty = false,
  flags = { bsphere = false, bbox = true, outline = true, text = true },
  filter = "?",
  active = false
  }'

Note that in this case, the content of 12866846752895976527 would be '{...}', with ' included.

So indeed, it is not an error with configparser, but an error in how the content of the INI file is written.

added
pendingThe issue will be closed if no feedback is provided
on May 23, 2025
PhilippKosarev

PhilippKosarev commented on May 23, 2025

@PhilippKosarev
Author

Yeah, the issue does seem to be in the INI fille itself, and adding an indentation before }' does fix the error.

Thank you for the thorough explanation :)

removed
type-bugAn unexpected behavior, bug, or error
pendingThe issue will be closed if no feedback is provided
on May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      configparser throws ParsingError when reading ini file · Issue #134516 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant