Reputation: 611
My simple python flask application failed to connect to redshift database. Logged error :
psycopg2.OperationalError: could not create SSL context: library has no ciphers FATAL: no pg_hba.conf entry for host "::ffff:0.0.0.0", user "admin", database "redshiftdb", SSL off
But when I the try same connection works well with simple python(simple.py) without flask.
import psycopg2
conn = psycopg2.connect(database="redshiftdb", user = "admin", password = "admin!pwd", host = "remotehost", port = "5439")
print ("Opened database successfully")
but with flask it does not work (init.py).
from flask import Flask
import psycopg2
@app.route("/service")
def service():
conn = psycopg2.connect(database="redshiftdb", user = "admin", password = "admin!pwd", host = "remotehost", port = "5439")
return "Service is running!"
if __name__ == "__main__":
app.run()
Upvotes: 1
Views: 1441
Reputation: 611
Finally following installations fixed the issue.
sudo apt-get install libpq-dev python-dev
sudo apt-get install python3-psycopg2
After this installation, I reinstalled psycopg2
pip3 install psycopg2
I don't know theory behind this fix, why and how it works.
Upvotes: 0
Reputation: 21
Try to build psycopg2 from source
pip install -r requirements.txt
Inlcude in requirements.txt
psycopg2==2.7.5 --no-binary :all:
Upvotes: 2