如何根据 SQL workbench 中的 URI 设置 psycopg2 参数?

How to set the psycopg2 parameters given the URI in SQL workbench?

来自这个SQL workbench tutorial

给定 URI:

jdbc:redshift://sample.redshift.openbridge.io:5439/sample_database?ssl=true&sslfactory=com.amazon.redshift.ssl.NonValidatingFactory

此外,我只需要 UsernamePassword 连接到 AWS 上的 redshift 服务器。

如果我在 Python 中使用 psycopg2,我需要以下字段来建立与数据库的连接:

例如

import psycopg2
con=psycopg2.connect(dbname= 'dbname', host='host', 
                     port= 'port', user= 'user', password= 'pwd')
con.connect()

鉴于上面显示的 URI,我计算出这些值:

但我认为我尝试从 URI 中拆分出来的值是错误的:

import psycopg2
dbname='sample.redshift.openbridge.io'
host='jdbc:redshift'
port=5439
user='Username'
password='Password'
con=psycopg2.connect(dbname, host, port, user, password)

OperationalError: could not translate host name "jdbc:redshift:" to address: nodename nor servname provided, or not known

给定上述 URI,psycopg2 参数的适当值是多少?

ssl=truesslfactory=com.amazon.redshift.ssl.NonValidatingFactory 设置和 sample_database数据库? 如何将这些设置为 psycopg2 中的 con 参数?

我的环境设置:


我可以使用它:

import psycopg2
dbname='sample_database'
host='sample.redshift.openbridge.io'
port=5439
user='Username'
password='Password'
con=psycopg2.connect(dbname, host, port, user, password)

但我不确定为连接设置的 ssl 属性。

我按上面的方式通过psycopg2连接的时候是ssl=truesslfactory=com.amazon.redshift.ssl.NonValidatingFactory吗?

psycopg2 是否自动将 jdbc:redshift 设置为协议?

来自URL:

jdbc:redshift://sample.redshift.openbridge.io:5439/sample_database?ssl=true&sslfactory=com.amazon.redshift.ssl.NonValidatingFactory

host: sample.redshift.openbridge.io
port: 5439
database: sample_database