1

我正在尝试使用 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"
}

我通过 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))

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

4

2 回答 2

2

尝试state从身体上取下钥匙。

IE

body = {
  "conf": {},
  "dag_run_id": "string",
  "execution_date": "2021-04-15T14:04:43.602Z"
}

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

于 2021-04-16T11:59:22.643 回答
0

可以通过以下方式解决它:

import requests
import json

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

auth = ('test', 'test')

body = {
  "conf": {},
}

r = requests.post("http://127.0.0.1:8080/api/v1/dags/sleeper/dagRuns",
                   headers=headers, 
                   auth=auth, 
                   data=json.dumps(body)
                 )

见链接:http://localhost:8080/api/v1/ui/#/DAGRun/post_dag_run

于 2021-11-06T01:31:36.447 回答