Closed superteece closed 4 years ago
Are you using your own code, or is this with this tutorial's code?
It’s the tutorial code, changing the .env DATABASE_URL entry to the FQDN or IP address of a MySQL db served on another VM. A remote db instead of localhost.
I just double checked. After cloning a fresh copy, checking out ch16, making a fresh db on both localhost and the remote host as per ch17, creating the .env as per ch17:
flask db migrate
& flask db upgrade
succeed when .env has localhost as DATABASE_URL
flask db migrate
& flask db upgrade
fail for the same error as in the original post when .env has the remote host as DATABASE_URL.
The VMs are CENTOS 8. The databases are on MariaDB.
It certainly seems to line up with issues known to stem from multi-threading I just don't understand the suggested fixes and came here hoping I wasn't the first ask about it.
Stack trace, if it helps: https://gist.github.com/superteece/fad2469cdb05ce93303766299ba01adf
Can you connect to the database using a different client, from the same host where you are running the Python app?
Ahh yes, thank you. Simplified troubleshooting is best troubleshooting. I had not granted a user with remote access to the DB. I've now done that and the connection works from the Flask app. Thank you for the quick and patient responses.
Summary:
Attempting to connect from PyMySQL (via flask-sqlalchemy // sqlalchemy) to a remote hosted MariaDB with a SQL user who is NOT granted remote access results in the error sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
Granting the user remote access like so: GRANT ALL ON microblog.* TO 'microblog'@'<remote_ip>' IDENTIFIED BY '<password>';
immediately clears the issue.
My DB works fine after Chapter 17 so long as mysql is on localhost. I'm trying to use a separate VM as the SQL server by changing the address in the .env file but any attempt to
flask db migrate
orflask db upgrade
results insqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
Research is pointing to an issue with pymysql connection pooling but finding a solution is proving difficult.
Any pointers?