http - 如何使用REST API触发Airflow Dag

标签 http go airflow

我正在尝试通过https://airflow.apache.org/docs/stable/api.html这个站点来触发气流障碍。他们提供了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(`{}`)
它像魅力一样运作。

关于http - 如何使用REST API触发Airflow Dag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60520083/

相关文章:

winapi - golang中的windows加密rdp密码

go - 在 Golang 中错误下划线,无需解释

airflow - MultiTennant Airflow - 访问控制和 secret 管理

HTTP post multipart-form 数据长度格式?

http - Nginx http 和 https block 配置

multithreading - 在 Go 中,如果您写入封闭 channel 会发生什么?我可以将 channel 视为确定性 RE 销毁吗?

python - 如何在 Airflow 中通过 SSH 并运行 PythonOperator

http - HTTP 响应头 Authorization 是否可以从服务端进行管理?

python - 使用 python 和 http 函数检查网络服务器中是否存在文件夹

python - 如何停止 Airflow 预定的 dag