1
votes

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()
  • ubuntu v12
  • Python version : 3.4
  • psycopg2==2.7.5
  • psycopg2-binary==2.7.5
  • Flask==1.0.2
2

2 Answers

2
votes

Try to build psycopg2 from source

pip install -r requirements.txt

Inlcude in requirements.txt

psycopg2==2.7.5 --no-binary :all:
0
votes

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.