Hi PythonAnywhere wizards, I have exactly the same error:
Error running WSGI application
2022-01-14 01:41:28,147: sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError)
(1045, "Access denied for user 'USER'@'10.0.0.123' (using password: YES)")
I use environment variables, here is a code snippet:
USER = os.getenv("USER")
DP = os.getenv("DP")
DB = os.getenv("DB")
# SQL engine
engine = db.create_engine('mysql+pymysql://USER:DP@icos.mysql.pythonanywhere-services.com/DB')
connection = engine.connect()
metadata = db.MetaData()
Is there something wrong with this code? I tried to find answers elsewhere on the Internet but I am still stuck with this issue. I have a doubt about special characters. I tried putting credentials in plain text (just for testing, I don't want this option for security purposes), without escaping special characters and it worked, escaping them, it didn't. I am also wondering if I should put USER, DP and DB between brackets or something similar in here : engine = db.create_engine('mysql+pymysql://USER:DP@icos.mysql.pythonanywhere-services.com/DB')
Other than that, I followed the instructions here to set up environment variables: https://help.pythonanywhere.com/pages/environment-variables-for-web-apps/
I tried mysql -u USERNAME -h HOSTNAME -p 'USERNAME$DATABASENAME' and it works after changing the password to one without special characters.
Can you help please?