I am making an office management system using Flask and I'm new to it. I'm getting this error which I do not know why is occurring. I have checked the data in my db.yaml file, and it is a-okay. Can someone help me get past this error.
app.py
from flask import Flask, render_template, request
from flask_mysqldb import MySQL
import yaml
app = Flask(__name__)
db = yaml.safe_load(open('db.yaml'))
app.config['MySQL_HOST'] = db['mysql_host']
app.config['MySQL_USER'] = db['mysql_user']
app.config['MySQL_PASSWORD'] = db['mysql_password']
app.config['MySQL_DB'] = db['mysql_db']
mysql = MySQL(app)
@app.route('/')
def output():
return db['mysql_db']
@app.route('/home')
def index():
return render_template('index.html')
@app.route('/log_in/<string:name>', methods=['GET', 'POST'])
def manager_log_in(name):
if request.method == 'POST':
# Fetching HTML Data
userDetails = request.form
username = userDetails['username']
password = userDetails['password']
# Fetching Database Data
cur = mysql.connect.cursor()
cur.execute(f"SELECT * FROM {name};")
data = cur.fetchall()
username_exists = False
if username in data[:]['username']:
username_exists = True
password_matches = False
cur.execute(f"SELECT password FROM {name} WHERE username = {username};")
actual_password = cur.fetchall()
actual_password = actual_password[0]['password']
if actual_password == password:
password_matches = True
if username_exists and password_matches:
return 'LOGGED IN SUCCESSFULLY'
else:
return 'INCORRECT USERNAME OR PASSWORD'
return render_template('log_in.html', name=name.capitalize())
if __name__ == '__main__':
app.run(debug=True)
output
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'hp'@'localhost' (using password: NO)")
log_in.html
{% extends 'base.html' %}
{% block title %}Log_In{% endblock %}
{% block head %}
<!-- Head Stuff -->
{% endblock %}
{% block body %}
<h1>{{ name }} Log_In</h1>
<form action='' method='POST'>
Username: <input type='text' name='username' id='username_entry'>
<br>
Password: <input type='password' name='password' id='password_entry'>
<br>
<input type='submit' name='submit_button' id='submit_button'>
</form>
<hr>
{% endblock %}
I have attached the code files where the error might be possibly occurring from.