Hello, I need a bit of help! I've looked through the forums and there were not many posts on this. I'm not sure why but when running SSH on my local jupyter notebook, I'm unable to connect and keep getting an error.
I've tried using the basic code provided, just to determine a connection:
import sshtunnel
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
with sshtunnel.SSHTunnelForwarder(
('ssh.pythonanywhere.com'),
ssh_username="jemm88",
ssh_password="login_password",
remote_bind_address=(jemm88.mysql.pythonanywhere-services.com', 3306)
) as server:
print('Server connected via SSH')
I'm a paid account, made sure that my username was case sensitive, and I've managed to connect to the DB with DBeaver and MySQLBench and am able to read and write data, so I know it's unlikely due to a firewall issue.
The error message I get is:
2022-09-01 14:57:06,524| ERROR | Could not connect to gateway ssh.pythonanywhere.com:22 : Unable to connect to ssh.pythonanywhere.com: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
The full code I was going to use, came from https://www.pythonanywhere.com/forums/topic/12295/, adjusted per comments to make it work.
import pandas as pd
from sqlalchemy import create_engine
import sshtunnel
sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0
host = '127.0.0.1'
user = 'myuser'
passwd = 'mycode'
db = 'myuser$dbname'
with sshtunnel.SSHTunnelForwarder(
('ssh.pythonanywhere.com'),
ssh_username="pythonanywhere_username",
ssh_password="pythonanywhere_passwd",
remote_bind_address=('myuser.mysql.pythonanywhere-services.com', 3306)
) as server:
print('Server connected via SSH')
port = str(server.local_bind_port)
conn_addr = 'mysql://' + user + ':' + passwd + '@' + host + ':' + port + '/' + db
print("[SQL] Trying to connect to " + conn_addr)
engine =create_engine(conn_addr, pool_recycle=280)
print('[SQL] Connexion established on ' + conn_addr)
dataDF = pd.read_sql('SHOW TABLES from myuser$dbname', engine)
print(dataDF)