通过 Airflow 运行作业时出现 Invalid Access Token 错误Invalid Access Token error when running jobs with Airflow

问题Problem

运行计划的 Airflow Azure Databricks 作业时,出现以下错误:When you run scheduled Airflow Azure Databricks jobs, you get this error:

Invalid Access Token : 403 Forbidden Error

原因Cause

若要通过 Airflow 运行或计划 Azure Databricks 作业,需要使用 Airflow Web UI 配置 Azure Databricks 连接。To run or schedule Azure Databricks jobs through Airflow, you need to configure the Azure Databricks connection using the Airflow web UI. 以下任何错误设置都可能导致错误:Any of the following incorrect settings can cause the error:

  • host 字段设置为 Azure Databricks 工作区主机名。Set the host field to the Azure Databricks workspace hostname.
  • login 字段设置为 tokenSet the login field to token.
  • password 字段设置为 Azure Databricks 生成的个人访问令牌。Set the password field to the Azure Databricks-generated personal access token.
  • Extra 字段设置为 JSON 字符串,其中的密钥是 token ,值是你的个人访问令牌。Set the Extra field to a JSON string, where the key is token and the value is your personal access token.

Azure Databricks 生成的个人访问令牌的有效期通常为 90 天。The Azure Databricks-generated personal access token is normally valid for 90 days. 如果令牌过期,则会发生此 403 Forbidden ErrorIf the token expires, then this 403 Forbidden Error occurs.

解决方案Solution

  • 验证 Extra 字段是否已使用 JSON 字符串正确配置:Verify that the Extra field is correctly configured with the JSON string:

    {"token": "<your personal access token>"}
    
  • 验证 password 字段和 Extra 字段中是否都提及了该令牌。Verify that the token is mentioned in both the password field and the Extra field.

  • 验证 hostloginpassword 字段是否均已正确配置。Verify that the host, login, and password fields are configured correctly.

  • 验证个人访问令牌是否未过期。Verify that the personal access token has not expired.

如有必要,可生成新令牌If necessary, generate a new token.