我正在使用Docker上的Airflow和Postgres。 我有以下连接,在其中执行DML命令(在Airflow之外):
# 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容器可在localhost:5433上访问。我可以完美地使用Pgadmin并从Python执行DML命令。
我实例化了Postgress(
db
对象)类,并在DAG中创建了以下任务:insert_into = PythonOperator(
task_id='insert_into',
python_callable=db.insert_into
)
然而,当我打开Airflow用户界面时,此消息弹出,我无法运行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?
我正在使用这个 Dockerfile来运行Airflow。我也在Airflow UI的“连接”部分尝试过,但是收到了相同的消息。我确定连接已经成功运行。