Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configparser.MissingSectionHeaderError: File contains no section headers. #520

Open
yejue opened this issue Jan 11, 2025 · 2 comments
Open
Assignees

Comments

@yejue
Copy link

yejue commented Jan 11, 2025

I encountered a very strange problem. I just used the following code to import pydantic_settings.

from pydantic_settings import BaseSettings
print("hello world")

But the following error was displayed:

root@ubuntu:~/projects/SightlessGuide2# python test.py 
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from pydantic_settings import BaseSettings
  File "/usr/local/lib/python3.8/dist-packages/pydantic_settings/__init__.py", line 1, in <module>
    from .main import BaseSettings, CliApp, SettingsConfigDict
  File "/usr/local/lib/python3.8/dist-packages/pydantic_settings/main.py", line 14, in <module>
    from .sources import (
  File "/usr/local/lib/python3.8/dist-packages/pydantic_settings/sources.py", line 40, in <module>
    from pydantic import AliasChoices, AliasPath, BaseModel, Json, RootModel, TypeAdapter
  File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
  File "/usr/local/lib/python3.8/dist-packages/pydantic/__init__.py", line 421, in __getattr__
    module = import_module(module_name, package=package)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.8/dist-packages/pydantic/root_model.py", line 35, in <module>
    class RootModel(BaseModel, typing.Generic[RootModelRootType], metaclass=_RootModelMetaclass):
  File "/usr/local/lib/python3.8/dist-packages/pydantic/_internal/_model_construction.py", line 224, in __new__
    complete_model_class(
  File "/usr/local/lib/python3.8/dist-packages/pydantic/_internal/_model_construction.py", line 620, in complete_model_class
    cls.__pydantic_validator__ = create_schema_validator(
  File "/usr/local/lib/python3.8/dist-packages/pydantic/plugin/_schema_validator.py", line 38, in create_schema_validator
    plugins = get_plugins()
  File "/usr/local/lib/python3.8/dist-packages/pydantic/plugin/_loader.py", line 39, in get_plugins
    for entry_point in dist.entry_points:
  File "/usr/lib/python3.8/importlib/metadata.py", line 240, in entry_points
    return EntryPoint._from_text(self.read_text('entry_points.txt'))
  File "/usr/lib/python3.8/importlib/metadata.py", line 100, in _from_text
    config.read_string(text)
  File "/usr/lib/python3.8/configparser.py", line 723, in read_string
    self.read_file(sfile, source)
  File "/usr/lib/python3.8/configparser.py", line 718, in read_file
    self._read(f, source)
  File "/usr/lib/python3.8/configparser.py", line 1082, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.

I wanted to look from the bottom to find out which f caused it and what it was. when I added print and reran it, the code was correct.
image

@yejue
Copy link
Author

yejue commented Jan 11, 2025

My System Info:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

My Package Info:

pydantic               2.10.5              
pydantic-core          2.27.2              
pydantic-settings      2.6.1   

@hramezani
Copy link
Member

I couldn't reproduce the problem. can you try it in a fresh env?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants