2017-09-27 83 views
0

我試着使用Peewee與sshtunnel連接到遠程MySQL數據庫:我可以用sshtunnel使用Python Peewee嗎?

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

你能幫助我嗎?

回答

0

你可能需要包括你已經從server對象綁定的隧道本地端口:

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

爲例見here

相關問題