Forums

Getting Internal server error whenever tried to connect to database

Whenever I comment

mydb = connector.connect(host="harshitrathore3.mysql.pythonanywhere-services.com", user='harshitrathore3', password="Harshit1", database = 'contact')
mydb.close()

this 2 line the code work fine but not work with these 2 lines my code below //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

from flask import Flask, request
from mysql import connector

app = Flask(__name__)

@app.route('/', methods=['GET'])
def home_page():
    return "pls go to login/signup page to login or signup"

@app.route("/login/", methods=['GET'])
def login_page():
    mydb = connector.connect(host="harshitrathore3.mysql.pythonanywhere-services.com", user='harshitrathore3', password="Harshit1", database = 'contact')
    mydb.close()

    return "server successfully runner"

Did you check your web app's error log? You should probably see something like ERROR 1044 (42000): Access denied for user 'USERNAME'@'%' to database 'USERNAME' there -- you should use different name of the database, probably "harshitrathore3$contact", since this is its full name. Have a look at this help page for more details.