1

I have been using a postgres database with pgAdmin3, and have never had any issues with connecting to the database. Today I tried accessing the database through Python using the following code:

import psycopg2
conn_string = "dbname='db0r0373s42fkg' user='ucaj9jki7hfthu' host='ec2-107-20-189-29.compute-1.amazonaws.com' password='secret'"
conn = psycopg2.connect(conn_string)
conn.close()

and I get the following error:

FATAL:  no pg_hba.conf entry for host "207.204.247.209", user "ucaj9jki7hfthu", database "db0r0373s42fkg", SSL off

From looking around this site, it seems that error occurs when the database is not set up to allow me to sign in with these credentials, but why does it work through pgadmin but not Python?

I saw another post with a similar question(Psycopg2 reporting pg_hba.conf error), but I didn't quite understand their answer and I'm not sure if I'm having the same problem Thanks so much for your help.

Community
  • 1
  • 1
user3658457
  • 275
  • 3
  • 11

2 Answers2

1

It looks like you have the same problem as this question: You're not connecting over SSL. Try passing sslmode='require' to psycopg2.connect.

Erin Call
  • 1,764
  • 11
  • 15
  • now it says: OperationalError: sslmode value "require" invalid when SSL support is not compiled in – user3658457 Jun 17 '15 at 22:02
  • blech. I think you need to reinstall python with SSL support. The specifics of that will depend on how you installed it originally. – Erin Call Jun 17 '15 at 22:08
  • hmm...could you point me in the right direction for doing that? i'm not sure where to get started. thanks again! – user3658457 Jun 17 '15 at 23:00
  • I would think the downloads on https://www.python.org/downloads/ would be compiled with SSL support. What OS are you on? – Erin Call Jun 18 '15 at 17:18
  • i'm on mac os x. i downloaded python using anaconda. i'll try reinstalling it directly from the python website. – user3658457 Jun 18 '15 at 18:44
  • Anaconda is one of the things I came across when I was researching the "compiled without ssl" error! Installing from the downloads page or from Homebrew should get you going. – Erin Call Jun 18 '15 at 19:48
0

Did you check what the poster said to check?
On your server run the following command:
cd /etc/postgresql/9.1/main/postgresql.conf

It might not be the same version so watch 9.1 but pretty much navigate to postgresql.conf. In this file will be the listed port. If running from the same machine make sure they aren't consuming the same port. pgadmin is using 5432 so make sure this file says it is as well.

FirebladeDan
  • 1,069
  • 6
  • 14