How to access the response from Airflow SimpleHttpOperator GET request

前端 未结 2 923
走了就别回头了
走了就别回头了 2021-01-04 23:50

I\'m learning Airflow and have a simple quesiton. Below is my DAG called dog_retriever

import airflow
from airflow import DAG
from airflow.opera         


        
2条回答
  •  春和景丽
    2021-01-05 00:19

    So since this is SimpleHttpOperator and the actual json is pushed to XCOM and you can get it from there. Here is the line of code for that action: https://github.com/apache/incubator-airflow/blob/master/airflow/operators/http_operator.py#L87

    What you need to do is set xcom_push=True, so your first t1 will be the following:

    t1 = 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)
    

    You should be able to find all JSON with return value in XCOM, more detail of XCOM can be found at: https://airflow.incubator.apache.org/concepts.html#xcoms

提交回复
热议问题