SSHTunnelForwarder:IP不是字符串错误

时间:2019-01-23 15:29:16

标签: python python-2.7 ssh-tunnel

我正在尝试使用SshTunnelForwarder编写脚本以通过ssh通过ssh连接到mysql服务器,如下所示:

import sshtunnel
import MySQLdb

def getValueFromDB(dbusername, query, ssh_pass, db_pass):
        with sshtunnel.SSHTunnelForwarder(("servername", 2222),
                                      ssh_password=ssh_pass,
                                      ssh_username=dbusername,
                                      remote_bind_address=("127.0.0.1", 3306)) as tunnel:
            conn = MySQLdb.connect("127.0.0.1", dbusername, db_pass, port=tunnel.local_bind_port)

            cursor = conn.cursor()
            cursor.execute(query)
            value = cursor.fetchone()[0]
            conn.close()
            return value

getValueFromDB("user", "show databases;", "pass1", "pass2")

但是我最终遇到错误:

    type(host).__name__
AssertionError: IP is not a string (NoneType)

尝试了所有可能的方法,但无济于事。 有人可以帮我解决问题吗?

我也尝试过使用“ ssh_address_or_host”,但是没有运气。

0 个答案:

没有答案
相关问题