问题
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