通过curl调用Airflow API触发DAG时出现400错误,请求格式待排查
问题解决:Airflow API触发DAG返回400 Bad Request错误
错误原因
Airflow 2.x的/api/v1/dags/{dag_id}/dagRuns POST接口要求请求必须携带JSON格式的请求体,接口期望接收一个object类型的参数。你当前的curl命令没有传递任何请求体,导致服务端接收到None,不符合参数类型要求,因此返回"None is not of type 'object'"的错误。
修复后的curl命令
1. 无参数触发DAG
只需传递一个空的JSON对象即可满足接口要求:
curl -X POST 'localhost:8080/api/v1/dags/my_dag/dagRuns' \ -H 'Content-Type: application/json' \ --user "admin:the_password" \ -d '{}'
2. 带自定义参数触发DAG
如果需要指定执行时间、传递任务参数等,可以在请求体中添加对应字段:
curl -X POST 'localhost:8080/api/v1/dags/my_dag/dagRuns' \ -H 'Content-Type: application/json' \ --user "admin:the_password" \ -d '{ "execution_date": "2024-05-20T00:00:00+00:00", "conf": { "param1": "value1", "param2": "value2" } }'
额外注意点
检查你的认证密码:GET请求中使用的是admin:thepassword,POST请求中是admin:the_password,两者存在字符差异,确认是否为笔误,避免因密码错误导致的认证失败。
内容的提问来源于stack exchange,提问作者HuLu ViCa
相关产品推荐
相关产品推荐

