How do I connect to Postgresql using SSL from SqlAchemy+pg8000?

白昼怎懂夜的黑 提交于 2019-11-28 10:00:44

问题


Connecting to postgres via pg8000 from SqlAlchemy worked fine until I enabled SSL on postgres.

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

Now it seems to fail with:

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:


probably you need to add connect_args dict:

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


来源:https://stackoverflow.com/questions/25095591/how-do-i-connect-to-postgresql-using-ssl-from-sqlachemypg8000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!