1

朋友们,

我正在尝试从运行在 EC2 机器上的 python 脚本连接到 AWS RDS 中的 Postgres 实例。它与 psycopg2/sqlalchemy 配合得很好

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()

但是当我使用 pg8000/sqlalchemy 作为

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()

错误信息是

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)

我也尝试设置connect_args={'ssl_context': True}连接但仍然失败。有人有什么想法吗?我正在使用 python v3.6、sqlalchemy v1.4.15 和 pg8000 v1.19.4。谢谢你。

4

0 回答 0