from sshtunnel import SSHTunnelForwarder server = SSHTunnelForwarder( 'pahaz.urfuclub.ru', ssh_username="pahaz", ssh_password="secret", remote_bind_address=('127.0.0.1', 3306) ) server.start() cxn = MySQLdb.connect(host='127.0.0.1',port=server.local_bind_port,user=DBUSER, passwd=DBPASSWD, db=DBNAME) return cxn server.start()