Accessing with python and sshtunnel not possible on Mac?

30 Views Asked by At

i try to access my mysql-database using a sshtunnel in python with the following code -

import mysql.connector
import sshtunnel

if __name__ == '__main__':
  with sshtunnel.SSHTunnelForwarder(
          ("xyz.a2hosting.com", 7822),
          ssh_username="myName",
          ssh_password="myPW",
          remote_bind_address=("0.0.0.0", 3306),
          local_bind_address=("127.0.0.1", 3306),
          allow_agent=False
  ) as tunnel:
      mydb = mysql.connector.connect(
          user="myUser",
          password="myPW",
          host="127.0.0.1",
          database="myDB",
          port="3306")
      c = mydb.cursor()
  print(f"Access is working fine!")

This works fine on my windows computer without problems.

But on my Mac i get the following error:

(openai) PolziMacs-Mini:colli239 polzimac$ python test1.py
2024-03-20 09:35:50,928| ERROR   | Password is required for key /Users/polzimac/.ssh/id_ed25519
2024-03-20 09:35:53,579| ERROR   | Problem setting SSH Forwarder up: Couldn't open tunnel 0.0.0.0:3306 <> 127.0.0.1:3306 might be in use or destination not reachable
Traceback (most recent call last):
  File "/Users/polzimac/Documents/DEV/Fiverr/TRY/colli239/test1.py", line 5, in <module>
    with sshtunnel.SSHTunnelForwarder(
  File "/Users/polzimac/Documents/DEV/venv/openai/lib/python3.9/site-packages/sshtunnel.py", line 1608, in __enter__
    self.start()
  File "/Users/polzimac/Documents/DEV/venv/openai/lib/python3.9/site-packages/sshtunnel.py", line 1344, in start
    self._raise(HandlerSSHTunnelForwarderError,
  File "/Users/polzimac/Documents/DEV/venv/openai/lib/python3.9/site-packages/sshtunnel.py", line 1174, in _raise
    raise exception(reason)
sshtunnel.HandlerSSHTunnelForwarderError: An error occurred while opening tunnels.

How can i run this also on my Mac-Computer?

0

There are 0 best solutions below