Код: Выделить всё
from config import settings
Код: Выделить всё
import os
from pydantic_settings import BaseSettings
def return_full_path(filename: str = ".env") -> str:
absolute_path = os.path.abspath(__file__)
directory_name = os.path.dirname(absolute_path)
full_path = os.path.join(directory_name, filename)
return full_path
class Settings(BaseSettings):
alpha_api_key: str
db_name: str
model_directory: str
class Config:
env_file = return_full_path(".env")
settings = Settings()
Код: Выделить всё
ValidationError Traceback (most recent call last)
in ()
11
12 from arch.univariate.base import ARCHModelResult
---> 13 from config import settings
14 from data import SQLRepository
~\Documents\Data Science\GARCH\config.py in ()
35 # Create instance of `Settings` class that will be imported
36 # in other modules for application.
---> 37 settings = Settings()
38
~\Anaconda3\lib\site-packages\pydantic_settings\main.py in __init__(__pydantic_self__, _case_sensitive, _env_prefix, _env_file, _env_file_encoding, _env_nested_delimiter, _secrets_dir, **values)
77 _env_file_encoding=_env_file_encoding,
78 _env_nested_delimiter=_env_nested_delimiter,
---> 79 _secrets_dir=_secrets_dir,
80 )
81 )
~\Anaconda3\lib\site-packages\pydantic\main.py in __init__(__pydantic_self__, **data)
162 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
163 __tracebackhide__ = True
--> 164 __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
165
166 # The following line sets a flag that we use to determine when `__init__` gets overridden by the user
ValidationError: 3 validation errors for Settings
alpha_api_key
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.5/v/missing
db_name
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.5/v/missing
model_directory
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.5/v/missing
Подробнее здесь: https://stackoverflow.com/questions/787 ... r-settings