我能用Python Peewee和sshtunnel吗?

2024-09-28 21:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试过使用Peewee和sshtunnel连接到远程mysql数据库:

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")

但我有个错误

^{pr2}$

你能帮帮我吗?在


Tags: pt数据库db远程serverwithmysqlusername
1条回答
网友
1楼 · 发布于 2024-09-28 21:29:45

您可能需要包括从server对象绑定隧道的本地端口:

myDb = pw.MySQLDatabase("dbname", host="localhost", port=server.local_bind_port, user="db_user", passwd="db_pass")

有关示例,请参见here。在

相关问题 更多 >