3

friends,

I'm trying to connect to a Postgres instance in AWS RDS from python script running in an EC2 machine. It's working well with psycopg2/sqlalchemy as

from sqlalchemy import create_engine 
import psycopg2

db_string = 'postgresql+psycopg2://{user}:{password}@{host}:5432/{database}'.format(
        user=DB_USER,
        password=DB_PASS,
        host=DB_HOST,
        database=DB_NAME)

engine = create_engine(db_string, echo=True)    
conn = engine.connect()

But it failed when I use pg8000/sqlalchemy as

from sqlalchemy import create_engine 
import pg8000

db_string = 'postgresql+pg8000://{user}:{password}@{host}:5432/{database}'.format(
        user=DB_USER,
        password=DB_PASS,
        host=DB_HOST,
        database=DB_NAME)

 engine = create_engine(db_string, echo=True)    
 conn = engine.connect()

The error info is

InterfaceError: (pg8000.exceptions.InterfaceError) {'S': 'FATAL', 'V': 'FATAL', 'C': '28000', 'M': 'no pg_hba.conf entry for host "*.*.*.*", user "*", database "*", SSL off', 'F': 'auth.c', 'L': '513', 'R': 'ClientAuthentication'}
(Background on this error at: http://sqlalche.me/e/14/rvf5)

I also tried to set the connect_args={'ssl_context': True} but still failed on the connection. Anyone has any thoughts? I'm using python v3.6, sqlalchemy v1.4.15, and pg8000 v1.19.4. Thank you.

Winter JJJ
  • 31
  • 3

0 Answers0