当我尝试通过python和使用psycopg2模块连接到redshift时,出现以下错误。
import psycopg2
my_db = 'dbname'
my_host = 'red-shift hostname'
my_port = '5439'
my_user = 'username'
my_password = 'password'
con = psycopg2.connect(dbname=my_db,host=my_host,port=my_port,user=my_user,password=my_password)
错误:
OperationalError: could not translate host name "redshift://redshift-cluster-1.cqxnjksdfndsjsdf.us-east-2.redshift.amazonaws.com" to address: Unknown host
答案 0 :(得分:0)
我遇到了类似的问题。尝试连接时似乎是SSL问题。 使用sqlalchemy-redshift连接到您的redshift集群,它将起作用。 这就是文档显示的连接方式
import sqlalchemy as sa
db_uri = 'redshift+psycopg2://username:password@redshift-cluster-1.cqxnxldsfjjbsdc.us-east-2.redshift.amazonaws.com:5439/dbname'
eng = sa.create_engine(db_uri)