Connecting to postgres via pg8000 from SqlAlchemy worked fine until I enabled SSL on postgres.
JavaScript
x
2
1
db = create_engine('postgresql+pg8000://user:pass@hostname/dbname', echo=True).connect()
2
Now it seems to fail with:
JavaScript
1
4
1
File "/Library/Python/2.7/site-packages/pg8000/core.py", line 872, in __init__
2
raise InterfaceError("communication error", exc_info()[1])
3
sqlalchemy.exc.InterfaceError: (InterfaceError) ('communication error', error(61, 'Connection refused')) None None
4
Advertisement
Answer
You need to add a connect_args
dict:
JavaScript
1
6
1
db = create_engine(
2
'postgresql+pg8000://user:pass@hostname/dbname',
3
connect_args={'sslmode':'require'},
4
echo=True,
5
).connect()
6