python-3.x - 如何使用 REST API 触发 Airflow dag(我得到 "Property is read-only - ' state'”,错误)

标签 python-3.x rest airflow directed-acyclic-graphs airflow-api

我正在尝试使用 REST API 触发 airflow 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 请求模块进行了尝试,结果是一样的。

例子:

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 中指定一些内容才能运行它? 因为据我所知,有些东西有权限? “属性是只读的 - 'state'”,

最佳答案

尝试从正文中删除 state 键。

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

Airflow REST API docs for that endpointstate 在正文中是必需的,但是您不需要在请求中包含它。我已经在本地 (Airflow v2.0.1) 测试了它,请求正文中没有 state,它似乎可以工作!

关于python-3.x - 如何使用 REST API 触发 Airflow dag(我得到 "Property is read-only - ' state'”,错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67110383/

相关文章:

python-3.x - pygame中的线碰撞

python - Django REST API 相关字段查询

Java:Jersey Rest 服务 URL 映射问题

airflow - 如何使用 Airflow 在不同的机器上运行一个工作流的不同任务?

python - for 循环无法正常运行?

python - 我们可以在 Beautifulsoup 中将所有 XML 标签转换为小写吗

python - 类型错误 : unsupported operand type(s) for -: 'str' and 'int'

json - Spring boot 启动器数据休息,@Notnull 约束不起作用

python - 如何从 Airflow 中的 Big Query 获取 SQL 查询的结果?