我正在尝试将flask dotenv与python-dotenv一起使用,但是我注意到Windwos 10上有一个问题。
在Mac和Linux上,一切正常,但是在运行flask应用程序的Windows上,出现异常。
它表明问题出在文件.flaskenv
上。如果我将文件从.flaskenv
重命名为_flaskenv
,就不会再有例外了,但是没有定义我的env变量。我也尝试手动加载此文件,但没有成功。 _flaskenv
未加载。
# .flaskenv
FLASK_APP=manage.py
FLASK_ENV=development
PS D:\practice\flask-dotenv> flask run
Traceback (most recent call last):
File "C:\Users\popam\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\popam\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\practice\flask-dotenv\venv\Scripts\flask.exe\__main__.py", line 9, in <module>
File "d:\practice\flask-dotenv\venv\lib\site-packages\flask\cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "d:\practice\flask-dotenv\venv\lib\site-packages\flask\cli.py", line 548, in main
load_dotenv()
File "d:\practice\flask-dotenv\venv\lib\site-packages\flask\cli.py", line 608, in load_dotenv
dotenv.load_dotenv(path)
File "d:\practice\flask-dotenv\venv\lib\site-packages\dotenv\main.py", line 309, in load_dotenv
return DotEnv(f, verbose=verbose).set_as_environment_variables(override=override)
File "d:\practice\flask-dotenv\venv\lib\site-packages\dotenv\main.py", line 138, in set_as_environment_variables
os.environ[k] = v
File "C:\Users\popam\AppData\Local\Programs\Python\Python37-32\lib\os.py", line 684, in __setitem__
self.putenv(key, value)
ValueError: embedded null character```