我可以将 Python Peewee 与 sshtunnel 一起使用吗?
Can I use Python Peewee with sshtunnel?
我尝试使用 Peewee 和 sshtunnel 连接到远程 mysql db:
with SSHTunnelForwarder(
('server.pt', 9922),
ssh_password="pass_ssh",
ssh_username="user_ssh",
remote_bind_address=('localhost', 3306)) as server:
myDB = pw.MySQLDatabase("dbname", user="db_user", passwd="db_pass")
但是我得到一个错误
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
你能帮帮我吗?
您可能需要包括您从 server
对象将隧道绑定到的本地端口:
myDb = pw.MySQLDatabase("dbname", host="localhost", port=server.local_bind_port, user="db_user", passwd="db_pass")
参见 here 示例。
我尝试使用 Peewee 和 sshtunnel 连接到远程 mysql db:
with SSHTunnelForwarder(
('server.pt', 9922),
ssh_password="pass_ssh",
ssh_username="user_ssh",
remote_bind_address=('localhost', 3306)) as server:
myDB = pw.MySQLDatabase("dbname", user="db_user", passwd="db_pass")
但是我得到一个错误
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
你能帮帮我吗?
您可能需要包括您从 server
对象将隧道绑定到的本地端口:
myDb = pw.MySQLDatabase("dbname", host="localhost", port=server.local_bind_port, user="db_user", passwd="db_pass")
参见 here 示例。