如何在Airflow中使用SimpleHttpOperator

5

当我运行以下代码时,出现错误:http_conn_id http_default未定义

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2020, 2, 27),
    'email': ['ss@asd.com'],
    'email_on_failure': True,
    'email_on_retry': True,
    'retries': 1,
    'retry_delay': timedelta(seconds=5),
}
dag = DAG(
    'dag1',
    default_args=default_args,
    description='A simple tutorial DAG',
    schedule_interval='@daily',
)
t2 = SimpleHttpOperator(
    task_id='get_labrador',
    method='GET',
    http_conn_id='http_default',
    endpoint='api/breed/labrador/images',
    headers={"Content-Type": "application/json"},
    xcom_push=True,
    dag=dag
)

我的http_conn_id值应该是什么?谢谢

1个回答

4

http_conn_id 应包含 Airflow 连接信息 的名称,该连接信息包含您想要连接的url详细信息。例如,要发送到Slack Webhook的主机名应为https://hooks.slack.com/

enter image description here


所以,如果我想要对 https://example.com/name/1 发出 GET 请求,那么我将创建一个 conn_var = https://example.comsimpleHttpOperator endpoint = /name/1 - Aseem
1
你需要从Airflow UI/CLI或使用环境变量创建连接: https://airflow.apache.org/docs/stable/howto/connection/index.html#creating-a-connection-with-the-ui ,然后将连接名称传递给http_conn_id。如果你想要对https://example.com/name/1进行GET请求,则输入主机名为https://example.com,并在你的任务中将endpoint设置为/name/1 - kaxil
如果它是静态值呢? - confiq

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接