I have a flask app that uses some enviroment variables, I don't now what has changed but now it doesn't read the variables in the .flaskenv file, already tried changing its name to .env, still not working.
This is the .flaskenv file:
FLASK_APP=app
FLASK_ENV=development
CONSUMER_KEY=
CONSUMER_SECRET=
ACCESS_KEY=
ACCESS_SECRET=
SEC_USERNAME=
SEC_PASSWORD=
In the app.py file:
from flask import Flask, render_template, url_for, request, redirect, session, g
import os
s_user = os.environ.get('SEC_USERNAME')
s_pass = os.environ.get('SEC_PASSWORD')
print(s_user)
print(s_pass)
if __name__ == "__main__":
app.run()
It prints "none".
If i do flask run :
Usage: flask run [OPTIONS]
Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.
For more information see http://flask.pocoo.org/docs/latest/quickstart/
pip list:
(venv) λ pip list
Package Version
----------------- ----------
certifi 2020.4.5.2
chardet 3.0.4
click 6.7
Flask 0.12.2
idna 2.9
itsdangerous 0.24
Jinja2 2.10
MarkupSafe 1.0
oauthlib 3.1.0
pip 19.2.3
PySocks 1.7.1
python-dotenv 0.13.0
requests 2.23.0
requests-oauthlib 1.3.0
setuptools 41.2.0
six 1.15.0
tweepy 3.8.0
urllib3 1.25.9
Werkzeug 0.13
env file inside the Python Flask application. Reads the key-value pair from the . env file and adds them to the environment variable. It is great for managing app settings during development and in production using 12-factor principles.
env is loaded exactly. Go doesn't handle . env natively, you're probably using godotenv. It sets the env variables for the current process (if using it as a library) and might work on windows.
Similarly, the FLASK_ENV variable sets the environment on which we want our flask application to run. For example, if we put FLASK_ENV=development the environment will be switched to development. By default, the environment is set to development. Now let us look at some example so that one can easily understand “what happens in reality”!
The .flaskenv isn't OS specific. It's loaded with the dotenv package, not anything related to the OS. And for the debug, ya you're right.
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory. This is a common error though. Normally, to fix this, we would export the environment variable FLASK_APP to be equal to the name of our app directory like this:
The .flaskenv isn't OS specific. It's loaded with the dotenv package, not anything related to the OS. And for the debug, ya you're right. It's a side effect of FLASK_ENV defaulting to production, which forces debug to false.
As written in the flask docs:
If python-dotenv is installed, running the flask command will set environment variables defined in the files .env and .flaskenv. This can be used to avoid having to set FLASK_APP manually every time you open a new terminal, and to set configuration using environment variables similar to how some deployment services work.
make sure to run pip install python-dotenv
This flask seems to be very old, try updating it with
pip install -U flask
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