I have uninstalled and reinstalled python-dotenv still i get same error. Could anyone sort this?
Some quick testing shows that it appeared in 0.10.4; with 0.10.3 no warning is displayed. Sorry, something went wrong. This is indeed surprising. It looks like your .env is fine so Python-dotenv shouldn't output a warning.
docker-compose uses python-dotenv for parsing env files. Keys can be unquoted, and single-quoted. Values can be unquoted, single- and double-quoted. Spaces before and after keys, equal signs, and values are ignored. Values can be followed by a comment.
docker-compose uses python-dotenv for parsing env files. Keys can be unquoted, and single-quoted. Values can be unquoted, single- and double-quoted. Spaces before and after keys, equal signs, and values are ignored.
Make sure your .env file only contains data in the following format:
MY_ENV_VAR = value
Anything other than this and you will get NoneType
if you are trying to retrieve them.
When you are trying to retrieve these you can do the following:
from pathlib import Path
from dotenv import load_dotenv
env_path = Path('.', '.env')
load_dotenv(dotenv_path=env_path)
my_env_var = os.getenv('MY_ENV_VAR')
The env_path
is simply the path to your .env
file. The '.' is the root directory of your app. You can even pass it in the dotenv_path
argument like '\path\to\your\.env'
e.g. load_dotenv(dotenv_path='\path\to\your\.env')
.
EDIT:
If you are adding it in your terminal, make sure there is no whitespace around the =
sign. For instance:
Linux:
$ export MY_ENV_VAR=value
Windows:
> set MY_ENV_VAR=value
For me the problem disappeared when I deleted space after equality sign and removed apostrophes ('
) and quotation marks ("
) from my .env file. So instead of this .env:
FOO = 'something'
BAR = "something_else"
Try changing .env to:
FOO=something
BAR=something_else
I'm seeing this too. It happens if the last line in the .env file is empty.
Some quick testing shows that it appeared in 0.10.4; with 0.10.3 no warning is displayed.
https://github.com/theskumar/python-dotenv/issues/235
This may helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With