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

Add encoding to read_env_file() #1615

Closed
erakli opened this issue Jun 9, 2020 · 2 comments · Fixed by #1620
Closed

Add encoding to read_env_file() #1615

erakli opened this issue Jun 9, 2020 · 2 comments · Fixed by #1620

Comments

@erakli
Copy link

erakli commented Jun 9, 2020

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'
@samuelcolvin
Copy link
Member

Sounds good to me, PR welcome.

@erakli
Copy link
Author

erakli commented Jun 9, 2020

@samuelcolvin looks like good guy @PrettyWood made one!

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

Successfully merging a pull request may close this issue.

2 participants