我正在使用 python 来测试 Airflow DAG。我有环境变量:
AIRFLOW_CONN_DB="postgresql://postgres:[email protected]:6099/db"
我使用以下命令来获取钩子来获取钩子:
hook = PostgresHook(postgres_conn_id="db")
然后我尝试将表格读取为数据框:
sql='select * from "schema_name".user;'
df = hook.get_pandas_df(sql)
但输出如下:
psycopg2.OperationalError:连接到“localhost”处的服务器(::1), 端口 5432 失败:连接被拒绝 (0x0000274D/10061) 是服务器 在该主机上运行并接受 TCP/IP 连接?连接到 服务器位于“localhost”(127.0.0.1),端口 5432 失败:连接 拒绝 (0x0000274D/10061) 服务器是否在该主机上运行并且 接受 TCP/IP 连接吗?
如何将连接设置为变量,以便我可以将其用作挂钩?
我重新阅读了文档。问题在于输入 postgresql (而不是 postgres)并在 url 中插入引号。 正确的环境是
AIRFLOW_CONN_DB=postgres://postgres:[email protected]:6099/db