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

Adds encoding parameter to read_env with default value 'utf8' #442

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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