Skip to content

Commit

Permalink
Merge pull request #442 from joke2k/fix/read_env-encoding
Browse files Browse the repository at this point in the history
Adds encoding parameter to read_env with default value 'utf8'
  • Loading branch information
sergeyklay authored Mar 1, 2023
2 parents 6948d3a + 8abbe77 commit a7d208c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ def search_url_config(cls, url, engine=None):
return config

@classmethod
def read_env(cls, env_file=None, overwrite=False, **overrides):
def read_env(cls, env_file=None, overwrite=False, encoding='utf8',
**overrides):
r"""Read a .env file into os.environ.
If not given a path to a dotenv path, does filthy magic stack
Expand All @@ -848,6 +849,7 @@ def read_env(cls, env_file=None, overwrite=False, **overrides):
the Django settings module from the Django project root.
:param overwrite: ``overwrite=True`` will force an overwrite of
existing environment variables.
:param encoding: The encoding to use when reading the environment file.
:param \**overrides: Any additional keyword arguments provided directly
to read_env will be added to the environment. If the key matches an
existing environment variable, the value will be overridden.
Expand All @@ -868,7 +870,7 @@ def read_env(cls, env_file=None, overwrite=False, **overrides):
try:
if isinstance(env_file, Openable):
# Python 3.5 support (wrap path with str).
with open(str(env_file), encoding='utf-8') as f:
with open(str(env_file), encoding=encoding) as f:
content = f.read()
else:
with env_file as f:
Expand Down

0 comments on commit a7d208c

Please sign in to comment.