直到我在postgres上启用SSL之前,从SqlAlchemy通过pg8000连接到postgres都工作良好。

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

最佳答案

可能您需要添加connect_args字典:

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

关于python - 如何使用来自SqlAlchemy + pg8000的SSL连接到Postgresql?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25095591/

10-12 19:26