Psycopg2 reports pg_hba.conf error

I came across a strange situation trying to use PostgreSQL and Psycopg2. For some reason, every time I try to connect to the postgre database via python, I get the following error:

psycopg2.OperationalError: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "steve", database "steve", SSL on
FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "steve", database "steve", SSL off

Naturally, I checked pg_hba.conf to find out what the problem was, but everything turned out to be configured correctly, as far as I can see:

pg_hba.conf:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

In addition, I found that I can connect to the database using psql, as expected:

$ psql -U steve -h 127.0.0.1
...
steve=>

Anyone have any ideas on what could be happening here? Thanks in advance!

+5
source share
2 answers

Typical explanations include:

+7

, .

:

  • ( python, django, psycopg2 postgres client 9.6.1 (postgresql-9.6.1.tar.gz)), ip address 10.0.0.1 ( ).
  • AWS postgres RDS "aws_rds_host_name" IP- .

:

django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host "10.0.0.1", user "your_user", database "your_db", SSL off

:

postgres client 9.6.1 10.0.0.1 <<2 → . postgres client .

  • postgres client source package 9.6.1 (postgresql-9.6.1.tar.gz)
  • postgresql-9.6.1.tar.gz.
  • ./configure --prefix="your_preferred_postgres_path_if_needed" --with-openssl (this '--with-openssl' , )
  • make install
  • , django psycopg2.

, -.

0

All Articles