如何通过REST API触发Airflow DAG?

3

1.10.0版本的文档说我可以通过在/api/experimental/dags//dag_runs上进行POST请求来触发DAG运行,但是当我这样做时,我收到了一个错误:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
2个回答

11
为了使它起作用,我想出了需要在主体中发送一个空的JSON字符串。
curl -X POST \
  http://airflow.dyn.fa.disney.com/api/experimental/dags/people_data/dag_runs \
  -H 'Cache-Control: no-cache' \
  -d '{}'

0

使用稳定的API REST/Airflow 2.x,我使用了:

从CLI:

curl -X POST "http://localhost:8080/api/v1/dags/taskflow_api/dagRuns" 
-H  "accept: application/json" -H  "Content-Type: application/json" \
-d "{}" \
--user "username:password"

使用Python库https://docs.python-requests.org/en/latest/中的request模块:
import requests
import json

headers = {
    'accept': 'application/json',
    'Content-Type': 'application/json'
}

auth = ('username', 'password')

body = {
       "conf": {}
}

response = requests.post(url=url,
                         headers=headers, 
                         auth=auth, 
                         data=json.dumps(body)
                        )

注意:要检查当前设置的身份验证后端,请参阅此链接 https://airflow.apache.org/docs/apache-airflow/stable/security/api.html

希望这非常有用

敬礼


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