1

I have a paid account with PythonAnywhere, with MySQL DB. I am able to connect to DB using DBeaver and am also able to SSH using command prompt (ssh[email protected]).

However when I use the same credentials to run the code in Jupyter Notebook in my local, I get the error:

Password is required for key C:\Users{myComputerUserName}/.ssh\id_rsa.... Could not connect to gateway ssh.pythonanywhere.com:22 :Incompatible ssh peer (no acceptable host key)

This is the notebook code I am using:

sshtunnel.SSH_TIMEOUT = 10.0sshtunnel.TUNNEL_TIMEOUT = 10.0with sshtunnel.SSHTunnelForwarder(    ('ssh.pythonanywhere.com'),    ssh_username='MyUserName', ssh_password='MyPWD',    remote_bind_address=('MyUserName.mysql.pythonanywhere-services.com', 3306)) as tunnel:    connection = MySQLdb.connect(        user='MyUserName',        passwd='MyPWD',        host='127.0.0.1', port=tunnel.local_bind_port,        db='MyUserName$DBName',    )    q1 = f"""SELECT session_key, session_data, expire_date        FROM django_session;"""    cursor = connection.cursor()    cursor.execute(q1)    print(cursor.fetchall())    connection.close()

I don't know much aboutSSH and am not able to figure out the issue. Have read all the PA and StackOverflow forums, but can't find an answer. Can someone point me in the right direction?

President Jam's user avatar
President Jam
1,3161 gold badge6 silver badges22 bronze badges
askedOct 16 at 1:10
chhibbz's user avatar

1 Answer1

1

Try using key-based auth inSSHTunnelForwarder (notssh_password):

import sshtunnelimport MySQLdb...with sshtunnel.SSHTunnelForwarder(    ('ssh.pythonanywhere.com', 22), # assuming your account is on www.pythonanywhere.com    ssh_username='MyUserName',    ssh_pkey=r'C:\Users\myComputerUserName}\.ssh\id_rsa',    # ssh_private_key_password='your_key_passphrase',  # only if your key has passphrase    remote_bind_address=('MyUserName.mysql.pythonanywhere-services.com', 3306),) as tunnel:    conn = MySQLdb.connect(        host='127.0.0.1', port=tunnel.local_bind_port,        user='MyUserName',        passwd='MyPWD',        db='MyUserName$DBName',    )    with conn as c:        ...

If you still see “no acceptable host key”, upgrade your client libs so they support modern host keys/algorithms:

pip install -U paramiko cryptography sshtunnel
answeredOct 16 at 8:11
caseneuve's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.