8000 Add encoding to `read_env_file()` · Issue #1615 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Add encoding to read_env_file() #1615

@erakli

Description

@erakli

Feature Request

Output of import pydantic.utils; print(pydantic.utils.version_info()):

             pydantic version: 1.5.1
            pydantic compiled: True
               python version: 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]
                     platform: Windows-7-6.1.7601-SP1
     optional deps. installed: ['email-validator']

Description

Hi, there's known problem on Windows with parsing dotenv files - pypa/pipenv#1963. python-dotenv would parse files with default encoding (cp1251 for Cyrillic Windows). As a result we get Лист 1 instead of Лист 1.

It looks like this function need to fetch encoding from Config class somehow.

Example

.env file (UTF-8):

foo=Лист 1

Code snippet:

import pydantic

class Settings(pydantic.BaseSettings):
    foo: str

    class Config:
        env_file_encoding = 'utf-8'

settings = Settings(_env_file='.env')
print(settings)
# foo='Лист 1'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0