【问题标题】:Apache Airflow - rest API AuthenticationApache Airflow - REST API 身份验证
【发布时间】:2020-04-20 18:56:01
【问题描述】:

我正在尝试使用 AirFlow 休息 API 触发我的 dag。但是无法理解如何进行身份验证。

以下 URL 在我的浏览器中运行良好。

http://localhost:8181/api/experimental/dags/demo/dag_runs

但是,以下代码给出了身份验证错误。

import requests
import json
from pprint import pprint


result = requests.get(
  "http://localhost:8181/api/experimental/dags/demo/dag_runs",
  data=json.dumps("{}"),
  auth=("myuser", "mypassword"))
pprint(result.content.decode('utf-8'))

我也发现了这个,但现在确定如何通过身份验证

https://github.com/apache/airflow/blob/master/airflow/api/client/api_client.py

【问题讨论】:

    标签: rest airflow airflow-scheduler


    【解决方案1】:

    默认情况下,REST API 拒绝所有请求。确保按照docs 中的说明设置 API 身份验证后端:

    [api]
    auth_backend = airflow.api.auth.backend.basic_auth
    

    【讨论】:

      【解决方案2】:

      1.- 您应该验证身份验证是否在您的 UI 上运行:

      http://localhost:8181/api/experimental/dags/demo/dag_runs

      此链接需要身份验证。

      2.- 您可以尝试的请求代码 sn-p 如下:

      curl --user USER_NAME:USER_PASSWORD -X POST \
      http://localhost:8181/api/experimental/dags/demo/dag_runs \
      -H 'Cache-Control: no-cache' \
      -H 'Content-Type: application/json' \
      -d "{}"
      

      节点中的相似代码:https://godatadriven.com/blog/using-the-airflow-experimental-rest-api-to-trigger-a-dag/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-15
        • 2019-03-31
        • 2018-07-26
        • 2019-08-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多