Not able to connect to remote database through ssh tunneling in python

家住魔仙堡 提交于 2020-04-30 12:21:04

问题


I'm trying to connect to a remote database through ssh tunneling. But I am getting an error when I try to connect. Below is my code and the error

def query(q):
    with SSHTunnelForwarder(
            ("bastion.example.co", 22),
            ssh_username="ubuntu",
            ssh_pkey="~/.ssh/id_rsa.pub",
            remote_bind_address=("127.0.0.1", 3306)
    ) as server:
        conn = mysql.connect(host="xyz.rds.amazonaws.com",
                          port=server.local_bind_port,
                          user="prod_db",
                          passwd="123abc",
                          db="prod_db")
        return pd.read_sql_query(q, conn)

print(query('select * from abc_table'))

Error:

Traceback (most recent call last):
  File "conn_mysql.py", line 20, in <module>
    print(query('select * from abc_table'))
  File "conn_mysql.py", line 11, in query
    remote_bind_address=("127.0.0.1", 3306)
  File "/Users/mohnishmallya/PycharmProjects/3Bvs2A/venv/lib/python3.7/site-packages/sshtunnel.py", line 904, in __init__
    logger=self.logger
  File "/Users/mohnishmallya/PycharmProjects/3Bvs2A/venv/lib/python3.7/site-packages/sshtunnel.py", line 1095, in _consolidate_auth
    raise ValueError('No password or public key available!')
ValueError: No password or public key available!

How do I solve this?

来源:https://stackoverflow.com/questions/57737400/not-able-to-connect-to-remote-database-through-ssh-tunneling-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!