Forums

SQL database not being opened

This is the error message I get:

Error running WSGI application
sqlite3.OperationalError: unable to open database file
File "/var/www/missile720_pythonanywhere_com_wsgi.py", line 16, in <module>
from genshin import app as application  # noqa

File "/home/missile720/mysite/genshin.py", line 20, in <module>
conn = sqlite3.connect(SQLALCHEMY_DATABASE_URI,check_same_thread=False)

My code:

genshin.py

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://missile720:genshinimpact@missile720.mysql.pythonanywhere-services.com/missile720$genshindata".format(
    username="the username from the 'Databases' tab",
    password="the password you set on the 'Databases' tab",
    hostname="the database host address from the 'Databases' tab",
    databasename="the database name you chose, probably yourusername$comments",
)

conn = sqlite3.connect(SQLALCHEMY_DATABASE_URI,check_same_thread=False)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config['SECRET_KEY'] = "thisissecret"

wsgi.py

import sys


path = '/home/missile720/mysite'
if path not in sys.path:
   sys.path.insert(0, path)


from genshin import app as application  # noqa

Is this bit of code copied literally?

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://missile720:genshinimpact@missile720.mysql.pythonanywhere-services.com/missile720$genshindata".format(
username="the username from the 'Databases' tab",
password="the password you set on the 'Databases' tab",
hostname="the database host address from the 'Databases' tab",
databasename="the database name you chose, probably yourusername$comments",

)

There are no placeholders for format call to interpolate. Also -- make sure that you have right settings for username, password etc. (if you just copied it from the help page, it obviously won't work, since you need to put your credentials there).

Also -- it looks like you want to use MySQL db, but your creating the connection with sqlite3, that also may cause errors.