Forums

flask_msqldb

Hi everyone,

I just installed flask-mysql by doing "pip3.6 install --user flask-mysql ". And when I want to import flask_mysqldb "from flask_mysqldb import MySQL" I got this:

Traceback (most recent call last): File "/home/acales/mysite/untitled.py", line 6, in <module> from flask_mysqldb import MySQL ModuleNotFoundError: No module named 'flask_mysqldb'

Do you know where this problem can come from?

Thank you for your help! Adam

Because Flask-mysql is not working I am using sqlalchemy now. This thing is, I have an error message when I want to access the database. Here is my code:

from flask import Flask from flask import render_template
#from urllib.request import urlopen from flask_sqlalchemy import SQLAlchemy from sqlalchemy import create_engine

app = Flask(__name__)

SQLALCHEMY_DATABASE_URI = "mysql://acales$POP_DB:<my_password>@acales.mysql.pythonanywhere-services.com/POP_DB"

app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI app.config["SQLALCHEMY_POOL_RECYCLE"] = 299 app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)

@app.route('/') def hello_world():
    return render_template('POPit_search.html')

@app.route('/getArticle') def getArticle():
    engine = create_engine(SQLALCHEMY_DATABASE_URI)
    engine.execute('SELECT * FROM t_articles')

I got this error message:

#012OperationalError: (_mysql_exceptions.OperationalError) (1045, "Access denied for user 'acales$POP_DB'@'10.0.0.27' (using password: YES)")

Because flask-mysql is not working I'm trying to use sqlachemy, but I have an error to connect to the database. Here is my code:

from flask import render_template
#from urllib.request import urlopen
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine

app = Flask(__name__)

SQLALCHEMY_DATABASE_URI = "mysql://acales$POP_DB:<my_password>@acales.mysql.pythonanywhere-services.com/POP_DB"

app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)

@app.route('/')
def hello_world():
    return render_template('POPit_search.html')

@app.route('/getArticle')
def getArticle():
    engine = create_engine(SQLALCHEMY_DATABASE_URI)
    engine.execute('SELECT * FROM t_articles')

And I got this message error:

#012OperationalError: (_mysql_exceptions.OperationalError) (1045, "Access denied for user 'acales$POP_DB'@'10.0.0.27' (using password: YES)")

Does someone had this error?

Thank you so much!

acales$POP_DB is not your username. it's the database name. Your username is acales.