通过Airflow dag运行REST API时出现405错误

时间:2019-03-07 22:32:03

标签: airflow

我正在尝试使用气流REST api(v1.10.2),但是任何时候我都想查询有关特定dag的信息时遇到问题。

以下是latest_runs端点工作的示例:

 ❯❯❯ curl -X GET http://192.168.99.100:30080/api/experimental/latest_runs
{
  "items": [
    {
      "dag_id": "test_dag",
      "dag_run_url": "/admin/airflow/graph?dag_id=test_dag&execution_date=2019-03-07+21%3A18%3A23.387031%2B00%3A00",
      "execution_date": "2019-03-07T21:18:23.387031+00:00",
      "start_date": "2019-03-07T21:18:23.683240+00:00"
    }
  ]
}

但是,当我尝试查询test_dag时出现错误:

 ❯❯❯ curl -X GET "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

我也尝试查找源代码,发现有一个state param可以使用:

 ❯❯❯ curl -X GET "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs?state=success"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

但是在其中添加似乎没有帮助。

我发现触发DAG可行:

 ❮❮❮ curl -X POST \
  http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs \
  -H 'Content-Type: application/json' \
  -d '{}'
{
  "message": "Created <DagRun test_dag @ 2019-03-07 22:31:18+00:00: manual__2019-03-07T22:31:18+00:00, externally triggered: True>"
}

任何人都知道为什么我无法查询DAG的状态并获得405吗?

编辑: 这是更多调查。我尝试使用所有可能的方法,但都不成功:

 4:21PM /Users/paymahn/solvvy/scheduler  ✘ 130 train.models ✭ ✱ ◼
 ❯❯❯ curl -X GET "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
 4:21PM /Users/paymahn/solvvy/scheduler train.models ✭ ✱ ◼
 ❯❯❯ curl -X OPTIONS "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
 4:21PM /Users/paymahn/solvvy/scheduler train.models ✭ ✱ ◼
 ❯❯❯ curl -X TRACE "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
 4:22PM /Users/paymahn/solvvy/scheduler train.models ✭ ✱ ◼
 ❯❯❯ curl -X PATCH "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
 4:22PM /Users/paymahn/solvvy/scheduler train.models ✭ ✱ ◼
 ❯❯❯ curl -X DELETE "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
 4:22PM /Users/paymahn/solvvy/scheduler train.models ✭ ✱ ◼
 ❯❯❯ curl -X HEAD "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the
Warning: way you want. Consider using -I/--head instead.
curl: (18) transfer closed with 178 bytes remaining to read
 4:22PM /Users/paymahn/solvvy/scheduler  ✘ 18 train.models ✭ ✱ ◼
 ❯❯❯ curl -X PUT "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
 4:22PM /Users/paymahn/solvvy/scheduler train.models ✭ ✱ ◼
 ❯❯❯ curl -X POST "http://192.168.99.100:30080/api/experimental/dags/test_dag/dag_runs"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>