如何使用 REST API 触发气流 dag(我收到“属性是只读的 - '状态'”,错误)

Jak*_*uta 4 rest directed-acyclic-graphs python-3.x airflow airflow-api

我正在尝试使用 REST API 触发气流 dags。这是行不通的。我收到 ERROR 400 响应:

{
  "detail": "Property is read-only - 'state'",
  "status": 400,
  "title": "Bad Request",
  "type": "https://airflow.apache.org/docs/2.0.1/stable-rest-api-ref.html#section/Errors/BadRequest"
}
Run Code Online (Sandbox Code Playgroud)

我通过 CURL 和 Python requests 模块进行了尝试,结果是相同的。

例子:

import requests

headers = {
    'accept': 'application/json',
    'Content-Type': 'application/json',
}
auth = ('test', 'test')
import json
body = {
  "conf": {},
  "dag_run_id": "string",
  "execution_date": "2021-04-15T14:04:43.602Z",
  "state": "success"
}
req = requests.post("http://127.0.0.1:8080/api/v1/dags/sleeper/dagRuns",
                   headers=headers, auth=auth, data=json.dumps(body))
Run Code Online (Sandbox Code Playgroud)

我是否需要在 Airflow 配置或 Dag 中指定某些内容才能运行它?因为据我了解,有一些具有权限的东西? "Property is read-only - 'state'",

Jos*_*osh 5

state尝试从机身上拔下钥匙。

IE

body = {
  "conf": {},
  "dag_run_id": "string",
  "execution_date": "2021-04-15T14:04:43.602Z"
}
Run Code Online (Sandbox Code Playgroud)

端点的 Airflow REST API 文档表示state正文中需要此内容,但您不需要将其包含在请求中。我已经在本地测试了它(Airflow v2.0.1),没有state在请求正文中,它似乎可以工作!