Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using sshtunnel on Mac? #290

Open
Rapid1898-code opened this issue Mar 20, 2024 · 1 comment
Open

Using sshtunnel on Mac? #290

Rapid1898-code opened this issue Mar 20, 2024 · 1 comment
Labels

Comments

@Rapid1898-code
Copy link

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=("127.0.0.1", 3306),
          local_bind_address=("0.0.0.0", 3306)
  ) 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.
(working directly when i run the code and also as an executable file creatd with pyinstaller)

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?

(i would like to run this code without any additonal adjustements in the terminal - so the python-code and the executable program when created with pyinstaller should run on any computer without having to do anything on the computer in the terminal - like it is working on windows)

@pahaz
Copy link
Owner

pahaz commented May 12, 2024

Password is required for key /Users/polzimac/.ssh/id_ed25519

As I can see, you need to provide an SSH key password.
And sshtunnel should work well on Mac.

@pahaz pahaz added the question label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants