Hello world! I am following the basic flask app tutorial and have checked and rechecked my code. It runs fine, without error but the resulting web page just shows 'Unauthorized' and the error log contains a line:
sqlalchemy.exc.ProgrammingError:(mysql.connector.errors.ProgrammingError) 1045 (28000): Access denied for user 'username'@'10.0.0.200' (using password: YES)
I am using the correct pw for the database. My PA username AND my database username is the same. Could that be the problem? If so, how do I delete my database and/or rename it? Any Help would be appreciated. I hate that I'm stuck on the basics... :(
from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["DEBUG"] = True
SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://user:pass@sameusername.mysql.pythonanywhere-services.com/user$comments"
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
if db:
print("\n\n",db)
print(app.config["SQLALCHEMY_DATABASE_URI"])
class Comment(db.Model):
__tablename__ = "comments"
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(4096))
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "GET":
return render_template("main_page.html", comments=Comment.query.all())
comment = Comment(content=request.form["contents"])
db.session.add(comment)
db.session.commit()
return redirect(url_for('index'))