我在Docker上使用气流和Postgres.我通过以下连接执行DML命令(外部气流):
# Constructor method initializing the connection to DB and creating cursor
def __init__(self, db="projeto-pos", user="postgres", host="localhost", password=my_psswd, port="5433"):
self.conn = psycopg2.connect(
database=db, host=host, port=port, password=password, user=user)
self.cur = self.conn.cursor()
我正在使用Docker,Postgres的容器可以在本地主机上找到:5433.我可以从Python中完美地使用Pgadmin和执行DML命令.
我实例化了Postgress(db
ojbect)类,并在DAG中创建了以下任务:
insert_into = PythonOperator(
task_id='insert_into',
python_callable=db.insert_into
)
但是,当我打开气流UI时,会弹出以下消息,我无法运行DAG:
Broken DAG: [/opt/airflow/dags/projeto_api.py] Traceback (most recent call last):
File "/opt/airflow/dags/functions/db_manipulation.py", line 10, in __init__
database=db, host=host, port=port, password=password, user=user)
File "/home/airflow/.local/lib/python3.7/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5433 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5433 failed: Cannot assign requested address
Is the server running on that host and accepting TCP/IP connections?
我使用this Dockerfile来实现气流.我也try 了在气流用户界面的"连接"部分,但我得到了相同的消息.我确信连接已启动并正在运行.