Hi I am trying to access the database of another user from my user. I wrote my python script based on the explanation on this link: https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere
Previously, it worked well. However, today I encountered an error.
Here is the error message:
2017-12-14 05:47:32,858: File "/home/adilab/.virtualenvs/webApp/lib/python3.5/site-packages/mysql/connector/network.py", line 243, in recv_plain
2017-12-14 05:47:32,858: raise errors.InterfaceError(errno=2013)
2017-12-14 05:49:59,729: Connected (version 2.0, client OpenSSH_7.2p2)
2017-12-14 05:49:59,868: Auth banner: b'<<<<<<:>~ PythonAnywhere SSH. Help @ https://help.pythonanywhere.com/pages/SSHAccess\n'
2017-12-14 05:49:59,868: Authentication (password) successful!
2017-12-14 05:50:04,879: 2017-12-14 05:50:04,879| ERROR | Could not establish connection from ('127.0.0.1', 36044) to remote side of the tunnel
2017-12-14 05:50:04,879: Could not establish connection from ('127.0.0.1', 36044) to remote side of the tunnel
Here is my python code:
import pandas as pd
import mysql.connector
import sshtunnel
def get_all_cols_from_a_table(conn, tableName):
sql_command = 'SELECT * FROM {tableName}'.format(tableName = tableName)
df = read_sql(sql_command, conn, chunksize = 10)
return df
def connect_to_mysql_and_get_pandas_df(databasename, username, password_pythonanywhere, password_db, hostname, tableName):
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
with sshtunnel.SSHTunnelForwarder(
('ssh.pythonanywhere.com'),
ssh_username=username, ssh_password=password_pythonanywhere,
remote_bind_address=(hostname, 3306)
) as tunnel:
connection = mysql.connector.connect(
user=username, password=password_db,
host='127.0.0.1', port=tunnel.local_bind_port,
database=databasename,
)
# Do stuff
df = get_all_cols_from_a_table(connection, tableName)
connection.close()
return df
Any clue? Thanks a lot.