Trying to connect to my database but I keep getting the following error:
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'mpm206'@'ip-10-63-166-201.ec2.internal' (using password: YES)")
I assume I'm making some kind of obvious mistake but I have no idea what:
from flask import Flask, abort, render_template, request, Response, redirect
from flask_bootstrap import Bootstrap
from flask.ext.sqlalchemy import SQLAlchemy
import SKapi, Spotify
import json, urllib.parse
from flask_wtf import Form
from wtforms import StringField, DateField
from wtforms.validators import DataRequired
# app instance
app = Flask(__name__)
# bootstrap instance
bootstrap = Bootstrap(app)
# configure app
app.config.from_object('config')
# mySQL
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(100), unique=True, index=True)
hash = db.Column(db.String(255))
cplace = db.Column(db.String(100))
cend = db.Column(db.String(10))
cstart = db.Column(db.String(10))
cpid = db.Column(db.Integer)
events = db.relationship('Events', backref='user', cascade="all, delete-orphan")
def __repr__(self):
return '<User %r>' % self.username
class Events(db.Model):
__tablename__ = 'saved'
id = db.Column(db.Integer, primary_key=True)
uid = db.Column(db.Integer, db.ForeignKey('users.id'))
evtid = db.Column(db.Integer)
artist = db.Column(db.String(255))
venue = db.Column(db.String(100))
addr = db.Column(db.String(255))
date = db.Column(db.String(10))
time = db.Column(db.String(40))
link = db.Column(db.String(255))
sample = db.Column(db.String(100))
Here's my config for the database with password substituted for the actual password.
SQLALCHEMY_DATABASE_URI = 'mysql://mpm206:password@mpm206.mysql.pythonanywhere-services.com/mpm206$bandflight'
Then I've just added this route to check the connection:
@app.route('/adduser')
def adduser():
new_user = User(username='mpm206', hash='password')
db.session.add(new_user)
db.session.commit()
return 'Success'
Where am I going wrong?