I have been banging my head against the wall trying to get this Flask web app running , which is really frustrating because it is only a preliminary to make sure all the modules and such are working correctly to be able to run a Flask app using SQLAlchemy.
I am running: Windows 10, python 3.6(latest) and latest pip install of SQLalchemy and flask
I am able to connect to the Heroku database that is listed under DATABASE_URI by using the CMD command: " psql [database_location] "
Here is the code I am running:
import os
from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
app = Flask(__name__)
app.config['DATABASE_URL'] = "postgres://jqnlclvhxpacdh:edc91a01d4ac2 ETC ETC ETC"
# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set")
# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
@app.route("/")
def index():
return "Project 1: TODO"
#
and here is the dump that python takes all over my screen when I try to run:
set FLASK_APP=application.py
(I made sure I am in the correct directory)
#Traceback (most recent call last):
File "c:\program files\python36\lib\site-packages\flask\cli.py", line 330, in __call__
rv = self._load_unlocked()
File "c:\program files\python36\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "c:\program files\python36\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "c:\program files\python36\lib\site-packages\flask\cli.py", line 242, in locate_app
'\n\n{tb}'.format(name=module_name, tb=traceback.format_exc())
flask.cli.NoAppException: While importing "application", an ImportError was raised:
Traceback (most recent call last):
File "c:\program files\python36\lib\site-packages\flask\cli.py", line 235, in locate_app
__import__(module_name)
File "C:\Program Files\Python36\learningPython\web_CS50\project1\application.py", line 4, in <module>
from flask_session import Session
File "c:\program files\python36\lib\site-packages\flask_session\__init__.py", line 16, in <module>
from .sessions import NullSessionInterface, RedisSessionInterface, \
File "c:\program files\python36\lib\site-packages\flask_session\sessions.py", line 23, in <module>
from itsdangerous import Signer, BadSignature, want_bytes
ImportError: cannot import name 'want_bytes'
#
I have tried running this by doing the setting the FLASK_APP[DATABASE_URL] in the command line to no avail, and have spent several hours on stackoverflow and here looking for some fix to this issue. I have reinstalled my python installation from anaconda to the latest python 3.6 and reinstalled all of the pip packages to no avail. Any advice on this point?