gpt4 book ai didi

python-2.7 - 断言错误 : INTERNAL: No default project is specified

转载 作者:行者123 更新时间:2023-12-01 00:25:07 27 4
gpt4 key购买 nike

新的 Airflow 。尝试运行 sql 并将结果存储在 BigQuery 表中。

得到以下错误。不确定在哪里设置 default_rproject_id。

请帮我。

错误:

Traceback (most recent call last):
File "/usr/local/bin/airflow", line 28, in <module>
args.func(args)
File "/usr/local/lib/python2.7/dist-packages/airflow/bin/cli.py", line 585, in test
ti.run(ignore_task_deps=True, ignore_ti_state=True, test_mode=True)
File "/usr/local/lib/python2.7/dist-packages/airflow/utils/db.py", line 53, in wrapper
result = func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/airflow/models.py", line 1374, in run
result = task_copy.execute(context=context)
File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/operators/bigquery_operator.py", line 82, in execute
self.allow_large_results, self.udf_config, self.use_legacy_sql)
File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/hooks/bigquery_hook.py", line 228, in run_query
default_project_id=self.project_id)
File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/hooks/bigquery_hook.py", line 917, in _split_tablename
assert default_project_id is not None, "INTERNAL: No default project is specified"
AssertionError: INTERNAL: No default project is specified

代码:
sql_bigquery = BigQueryOperator(
task_id='sql_bigquery',
use_legacy_sql=False,
write_disposition='WRITE_TRUNCATE',
allow_large_results=True,
bql='''
#standardSQL
SELECT ID, Name, Group, Mark, RATIO_TO_REPORT(Mark) OVER(PARTITION BY Group) AS percent FROM `tensile-site-168620.temp.marks`
''',
destination_dataset_table='temp.percentage',
dag=dag
)

最佳答案

编辑:我终于通过简单地添加 bigquery_conn_id='bigquery' 解决了这个问题在单独的 Python 脚本中运行以下代码后,BigQueryOperator 任务中的参数。

显然,您需要在 Airflow UI 的 Admin -> Connection 中指定您的项目 ID。您必须将其作为 JSON 对象执行,例如 "project": ""。

我个人无法让网络服务器在 GCP 上工作,所以这是不可行的。这里有一个程序化的解决方案:

from airflow.models import Connection
from airflow.settings import Session

session = Session()
gcp_conn = Connection(
conn_id='bigquery',
conn_type='google_cloud_platform',
extra='{"extra__google_cloud_platform__project":"<YOUR PROJECT HERE>"}')
if not session.query(Connection).filter(
Connection.conn_id == gcp_conn.conn_id).first():
session.add(gcp_conn)
session.commit()

这些建议来自 a similar question here.

关于python-2.7 - 断言错误 : INTERNAL: No default project is specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45626406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com