Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
279 stars 133 forks source link

.env was not load #110

Closed yc185048 closed 1 year ago

yc185048 commented 1 year ago

I was going through the example code and found the .env file was not load automatically. I added the following to app_config.py file

from dotenv import load_dotenv
load_dotenv()

Not sure if it is intended behavior. If not I can create a PR for this. Thanks.

rayluo commented 1 year ago

Quoted from Flask's documentation, it should automatically load .env:

If python-dotenv is installed, running the flask command will set environment variables defined in the files .env

Our sample does use python-dotenv, and it indeed automatically loads .env in my environment.

Does that not work for you? Which Flask and python-dotenv versions are you using?

yc185048 commented 1 year ago

My bad. I start up the app by running python app.py instead of using python -m flask run command. It would be good to add extra note for this behavior. Just my though. Thank you!

rayluo commented 1 year ago

My bad. I start up the app by running python app.py instead of using python -m flask run command. It would be good to add extra note for this behavior. Just my though. Thank you!

We will see what we can improve here. But can you provide more info?

I tried python app.py and it can still load .env. I want to reproduce your report in order to get to the bottom of this issue. Which Flask and python-dotenv versions are you using?

yc185048 commented 1 year ago

Sure. Here are the version info from my pip list Flask 2.2.5 Flask-Session 0.4.1 python-dotenv 0.21.1 Python 3.10.11

One other thing is I didn't use virtualenv for python env management. I use conda for the python and install package through pip and requirement files.