How to connect to a database through a Paramiko Tunnel (or similar package)

后端 未结 2 1363
予麋鹿
予麋鹿 2020-12-18 17:38

I am having serious issues setting up a proper tunnel in paramiko to enable a database connection. I have reviewed the example \'forward.py\', but am not understanding how

相关标签:
2条回答
  • 2020-12-18 17:50

    if you have created your ssh tunnel using the forward.py script ; you can use the ssh tunnel to connect to postgresql like this:

    conn = psycopg2.connect(database="test", host="localhost", port=<forward_port>)
    
    0 讨论(0)
  • 2020-12-18 17:59

    I had same serious issues getting paramiko to work too but ended up doing it with another library (sshtunnel) that wraps and simplifies paramiko's tunneling.

    You can check my answer in another similar question with some sample code to use it.

    0 讨论(0)
提交回复
热议问题