如何使用SqlAlchemy + pg8000中的SSL连接到Postgresql?

时间:2014-08-02 13:36:00

标签: python sqlalchemy pg8000

从SqlAlchemy通过pg8000连接到postgres工作正常,直到我在postgres上启用了SSL。

db = create_engine('postgresql+pg8000://user:pass@hostname/dbname', echo=True).connect()

现在似乎失败了:

File "/Library/Python/2.7/site-packages/pg8000/core.py", line 872, in __init__
raise InterfaceError("communication error", exc_info()[1])
sqlalchemy.exc.InterfaceError: (InterfaceError) ('communication error', error(61, 'Connection refused')) None None

1 个答案:

答案 0 :(得分:3)

可能你需要添加connect_args dict:

db = create_engine('postgresql+pg8000://user:pass@hostname/dbname', connect_args={'sslmode':'require'}, echo=True).connect()