【问题标题】:Authorisation error when running airflow via cloud composer通过 Cloud Composer 运行气流时出现授权错误
【发布时间】:2019-03-20 10:29:00
【问题描述】:

尝试使用 GoogleCloudStorageToBigQueryOperator 从云作曲家运行 DAG 时出现错误。

最终错误是:{'reason': 'invalid', 'location': 'gs://xxxxxx/xxxx.csv', 当我按照错误的 URL 链接...

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie     or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-    project.",
    "errors": [
      {
        "message": "Login Required.",
        "domain": "global",
        "reason": "required",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED"
  }
}

我已经配置了云存储连接...

Conn Id My_Cloud_Storage

Conn 输入谷歌云平台

项目 ID xxxxxx

密钥文件路径/home/airflow/gcs/data/xxx.json

密钥文件 JSON

范围(逗号分隔)https://www.googleapis.com/auth/cloud-platform

代码..

from __future__ import print_function

import datetime

from airflow import models
from airflow import DAG
from airflow.operators import bash_operator
from airflow.operators import python_operator
from airflow.contrib.operators.gcs_to_bq import GoogleCloudStorageToBigQueryOperator

default_dag_args = {
    # The start_date describes when a DAG is valid / can be run. Set this to a
    # fixed point in time rather than dynamically, since it is evaluated every
    # time a DAG is parsed. See:
    # https://airflow.apache.org/faq.html#what-s-the-deal-with-start-date
    'start_date': datetime.datetime(2019, 4, 15),
}
with models.DAG(
        'Ian_gcs_to_BQ_Test',
        schedule_interval=datetime.timedelta(days=1),
        default_args=default_dag_args) as dag:

    load_csv = GoogleCloudStorageToBigQueryOperator(
        task_id='gcs_to_bq_test',
        bucket='xxxxx',
        source_objects=['xxxx.csv'],
        destination_project_dataset_table='xxxx.xxxx.xxxx',
        google_cloud_storage_conn_id='My_Cloud_Storage',
        schema_fields=[
            {'name':'AAAA','type':'INTEGER','mode':'NULLABLE'},
            {'name':'BBB_NUMBER','type':'INTEGER','mode':'NULLABLE'},   
        ],
        write_disposition='WRITE_TRUNCATE',
        dag=dag)

【问题讨论】:

  • 您确定该错误与 BigQuery 无关,因为您没有指定 bigquery_conn_id 吗?
  • 我尝试创建大查询连接,但没有任何区别。它仍然是一个授权错误并且说位置无效,但我已经仔细检查了位置并且它是正确的。

标签: airflow google-cloud-composer


【解决方案1】:

好的,现在解决了。 事实证明,由于文件中的标题行,它不起作用,一旦我删除它就可以正常工作。 关于无效位置和授权的非常烦人的、完全误导性的错误消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-06
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多