Skip to content

Commit b7f5a67

Browse files
ausakitheskumar
authored andcommitted
fix bug: DotEnv._get_stream raise IOError when .env is a directory rather than a file (theskumar#120)
# How this bug happened ? The function `find_dotenv` try to find a file named `.env`, if there is a directory named `.env` by coincidence, then `DotEnv._get_stream` will raise IOError. # Fix this bug use `os.path.isfile` instead of `os.path.exists`.
1 parent ea0604d commit b7f5a67

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

dotenv/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _get_stream(self):
5757
if isinstance(self.dotenv_path, StringIO):
5858
return self.dotenv_path
5959

60-
if os.path.exists(self.dotenv_path):
60+
if os.path.isfile(self.dotenv_path):
6161
self._is_file = True
6262
return io.open(self.dotenv_path)
6363

@@ -241,7 +241,7 @@ def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
241241

242242
for dirname in _walk_to_root(path):
243243
check_path = os.path.join(dirname, filename)
244-
if os.path.exists(check_path):
244+
if os.path.isfile(check_path):
245245
return check_path
246246

247247
if raise_error_if_not_found:

0 commit comments

Comments
 (0)