I have problems using the following code it freezes before I get a connect message. Is there an alternative way to connect from outside python-anywhere?
import mysql.connector as sqlConnector
import sshtunnel
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
dbHostName='zzzzzz.mysql.pythonanywhere-services.com'
dbName='myDB$tendlc_db'
dbUserName='myDBuser'
dbUserPassword='xxxxxx!'
sshHostName='ssh.pythonanywhere.com'
pyUserName='myLogin'
pyPassWord='myPWD'
# Helper function to execute query
def dbtest():
with sshtunnel.SSHTunnelForwarder(
(sshHostName),
ssh_username=pyUserName, ssh_password=pyPassWord,
remote_bind_address=(dbHostName, 3306)
) as tunnel:
print ("SSH TUNNEL ESTABLISHED")
connection = sqlConnector.connect(
user=dbUserName, password=dbUserPassword,
host='127.0.0.1', port=tunnel.local_bind_port,
database=dbName,
)
print("CONNECTED")
connection.close()