#!/usr/bin/python
# -*- coding: UTF-8 -*-
from bs4 import BeautifulSoup
import pymysql
import re
from urllib import urlopen
import requests
import json
import math
from sshtunnel import SSHTunnelForwarder
with SSHTunnelForwarder(
('115.29.184.78',22), # B机器的配置
ssh_password='****',
ssh_username='root',
remote_bind_address=('*********',3268)) as server: # A机器的配置
db_connect = pymysql.connect(host='127.0.0.1', # 此处必须是是127.0.0.1
port=server.local_bind_port,
user='root',
passwd='123456',
db='uc')
cur = db_connect.cursor()
cur.execute('select 1 from dual')
data=cur.fetchone()
print(data[0])
转载于:https://my.oschina.net/u/3238650/blog/2877717