重新检查您的身份验证令牌是否已正确设置。以下提供了一个基本的身份验证示例代码,您可以将其添加到您的Airflow DAG文件中。您需要先安装python库requests。
import requests
from airflow.models import Variable
auth_token = Variable.get('my_auth_token')
# Set API endpoint URL
url = 'http://localhost:8080/api/experimental/dags'
# Set headers and authentication
headers = {
'Authorization': 'Bearer ' + auth_token,
'Content-Type': 'application/json'
}
# Test GET request
response = requests.get(url, headers=headers)
print(response.json())
为了使上述代码正常工作,请确保在Airflow Web界面的“Admin->Variables”中添加了名为“my_auth_token”的变量,并将其值设置为您的API身份验证令牌。