[英]How to trigger Airflow Dag using REST API
我正在尝试通过关注https://airflow.apache.org/docs/stable/api.html这个站点来触发 Airflow Dags。 他们提供了 curl 命令curl -X POST \\ http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \\ -H 'Cache-Control: no-cache' \\ -H 'Content-Type: application/json' \\ -d '{"conf":"{\\"key\\":\\"value\\"}"}'
触发 Dag。 当我从我的 Shell 执行这个命令时它正在工作。
我尝试在 Go POST /api/experimental/dags/<DAG_ID>/dag_runs
调用此端点,但收到400 Bad Request
如何在 Go 中使用POST /api/experimental/dags/<DAG_ID>/dag_runs
作为http.POST()
或http.NewRequest()
?
我试过这个:
package main
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
func main(){
body := strings.NewReader(`{"conf":"{\"key\":\"value\"}"}`)
req, err := http.NewRequest("POST", "http://localhost:8080/api/experimental/dags/airflow_sample/dag_runs", body)
if err != nil {
fmt.Println(err)
}
req.Header.Set("Cache-Control", "no-cache")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp)
defer resp.Body.Close()
}
我解决了。
在主要功能中 -
我改变了body := strings.NewReader(`{"conf":"{\\"key\\":\\"value\\"}"}`)
到这个body := strings.NewReader(`{}`)
它就像一个魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.