MySQL Forums
Forum List  »  Connector/Python

[BUG] v8.2.0 breaking with ssh tunnel
Posted by: Philip Heurich
Date: July 25, 2024 04:53AM

Hi,

Trying to run 8.2.0 of the mysql python connector with the sshtunnel package to connect to a remote server. The code is very simple and I used a new environment with bare minimum packages. It seems like 8.2.0 introduced a breaking change that makes the code hang at the mysql.connector.connect() call and times out. The same code on 8.1.0 works fine and produces the expected output.

from sshtunnel import SSHTunnelForwarder
import mysql.connector

# Define your SSH and database connection details
SSH_HOST = ''
SSH_PORT = 22
SSH_USERNAME = ''
SSH_PASSWORD = ''

DB_HOST = 'localhost'
DB_PORT = 3306  
DB_USER = ''
DB_PASSWORD = ''

with SSHTunnelForwarder(
    (SSH_HOST, SSH_PORT),
    ssh_username=SSH_USERNAME,
    ssh_password=SSH_PASSWORD,
    remote_bind_address=(DB_HOST, DB_PORT)
) as tunnel:
    local_port = tunnel.local_bind_port

    connection = mysql.connector.connect(
        host='127.0.0.1',
        port=local_port,
        user=DB_USER,
        password=DB_PASSWORD
    )

    cursor = connection.cursor()
    cursor.execute("SHOW DATABASES")
    databases = cursor.fetchall()

    for db in databases:
        print(db[0])

    cursor.close()
    connection.close()
-----

Python version 3.12.4
Installed packages

Package Version
---------------------- -------
bcrypt 4.2.0
cffi 1.16.0
cryptography 43.0.0
mysql-connector-python 8.1.0
paramiko 3.4.0
pip 24.0
protobuf 4.21.12
pycparser 2.22
PyNaCl 1.5.0
setuptools 69.5.1
sshtunnel 0.4.0
wheel 0.43.0

Options: ReplyQuote


Subject
Written By
Posted
[BUG] v8.2.0 breaking with ssh tunnel
July 25, 2024 04:53AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.