I have started this today and received this over again and again and I have recreated the user also but it is not working. Please help me to debug it.
This is my app.py
from flask import Flask, jsonify, render_template, request from flask_sqlalchemy import SQLAlchemy from datetime import datetime app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://taran:1234@localhost/flask' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class Post(db.Model): id = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(50), nullable = False) body = db.Column(db.String(200), nullable = False) date = db.Column(db.DateTime(timezone=True), default=datetime.now()) @app.route('/', methods = ['GET', 'POST']) def home(): title = request.form.get('title') body = request.form.get('body') post = Post(title = title, body = body) db.session.add(post) db.session.commit() return render_template('index.html') if __name__ == "__main__": app.run(debug= True)
Please help
check if the password to access your SQL database is correct or else try changing your SQL root password to something else and try again. The above error is very similar to the one we commonly encounter while logging on to a website with the wrong password or username.
for changing the root password see the below video https://youtu.be/izMuHGwXyjQ
If you don't have a password try either of this
Option 01:
SQLALCHEMY_DB_URI='mysql://root@localhost:<PORT>/<DB NAME>'
Option 02:
SQLALCHEMY_DB_URI='mysql://root:''@localhost:<PORT>/<DB NAME>'
Have you tried to change the driver?
#from
'mysql://taran:1234@localhost/flask'
#to
'mysql+pymysql://taran:1234@localhost/flask'
(I assume you've checked credentials already)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.