请问如何连接有SSH通道加密的数据库?

hal_sakai 2017-10-12 02:00:30
小弟新手,普通不加密的数据库通过sqlalchemy模块可以正常连接,现在碰到SSH加密通道就没辙了,目前是以公钥形式加的密,请问该如何在脚本中连接?现在连接的代码如下:

from sqlalchemy import create_engine
import numpy as np
import pandas as pd

engine = create_engine('postgresql://postgres:123456@localhost:5432/postgres')
df = pd.read_sql_query('select sum(setl_int_amt) from pay_log',con=engine)
...全文
374 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hal_sakai 2017-10-19
  • 打赏
  • 举报
回复
顶一下~~~~~
混沌鳄鱼 2017-10-19
  • 打赏
  • 举报
回复
如果不行, 先直接用psycopg2连接测试一下. 执行下面这段代码, 看看是不是报错.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psycopg2

conn = psycopg2.connect(host='127.0.0.1',  
                        port='5432',
                        database='postgres',
                        user='postgres',
                        password='12345',
                        sslmode='require')

cur = conn.cursor()

cur.execute('SELECT * FROM tablename')

如果不行可能是安装时没有带ssl支持. 在安装Psycopg2的时候,应该用源码安装, 编译程序时候带上 --with-openssl 选项.
混沌鳄鱼 2017-10-19
  • 打赏
  • 举报
回复
把连接字符串改一下试试. engine = create_engine('postgresql://postgres:123456@localhost:5432/postgres') 改成下面这样 engine = create_engine('postgresql://postgres:123456@localhost:5432/postgres[?sslmode=require]') 不敢保证对, 只是大约看了一下sqlalchemy的手册 http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#module-sqlalchemy.dialects.postgresql.psycopg2 还有postgress的手册 https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
hal_sakai 2017-10-15
  • 打赏
  • 举报
回复
顶一下~~~~~
hal_sakai 2017-10-13
  • 打赏
  • 举报
回复
没人回。。。

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧