# -*- coding:utf-8 -*-
import pymongo
from sshtunnel import SSHTunnelForwarder
server = SSHTunnelForwarder(
('跳板機ip', 40589),
ssh_password='跳板機密碼',
# -*- coding:utf-8 -*- import pymongo from sshtunnel import SSHTunnelForwarder server = SSHTunnelForwarder( ('跳板機ip', 40589), ssh_password='跳板機密碼', ssh_username='跳板機用戶', remote_bind_address=('阿里雲地址', 3717)) server.start() client = pymongo.MongoClient('127.0.0.1', server.local_bind_port) mongo_database = client['history_data'] print mongo_database mongo_database.authenticate('mongo用戶', 'mongo密碼') print mongo_database.collection_names() collection = mongo_database.t_credit_behavior print collection.find_one() client.close() server.stop()
參考文章:http://www.mamicode.com/info-detail-2119024.html