python - 气流找不到本地文件
问题描述
从 Airflow 使用 FileToGoogleCloudStorageOperator 时,我在运行我的 dag 时不断收到此错误:
"FileNotFoundError: [Errno 2] No such file or directory: '/Users/ramonsotogarcia/Desktop/Data/pokemon.csv"
我不明白为什么 Airflow 找不到我的本地文件。这是我的一天:
from datetime import timedelta
from airflow.contrib.operators.file_to_gcs import FileToGoogleCloudStorageOperator
from airflow.contrib.operators.gcs_to_bq import GoogleCloudStorageToBigQueryOperator
from airflow.utils.dates import days_ago
#define variables
file = "pokemon.csv"
bucket = "modulo_spark_bucket"
destination_path = f"gs://{bucket}/data/{file}"
bucket = f"gs://{bucket}"
local_file = f"/Users/ramonsotogarcia/Desktop/Data/{file}"
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': days_ago(2),
'email': ['sotogarcia.r@icloud.com'],
'email_on_failure': True,
'email_on_retry': False,
'retries': 3,
'retry_delay': timedelta(minutes=5),
}
my_dag = DAG(
'fileSystem_toGCS_toBQ',
default_args=default_args,
description='Loads data from local file into GCS and then transfer to BQ',
schedule_interval=None,
)
t1 = FileToGoogleCloudStorageOperator(task_id = "local_to_gcs",
src = local_file,
dst = destination_path,
bucket = bucket,
dag = my_dag)
t2 = GoogleCloudStorageToBigQueryOperator(task_id = "GCS_to_BQ",
bucket = bucket,
source_objects = [destination_path],
autodetect = True,
skip_leading_rows = 1,
create_disposition = "CREATE_IF_NEEDED",
destination_project_dataset_table = "neural-theory-277009.pokemon_data.pokemons",
dag = my_dag)
#dependencies
t1 >> t2
有任何想法吗?我似乎无法弄清楚出了什么问题。
解决方案
只是一个猜测,但您是否尝试过在文件路径中指定驱动器,即
f"C:/Users/ramonsotogarcia/Desktop/Data/{file}"
如果您的气流和 csv 在不同的磁盘上。
推荐阅读
- python - Oracle 数据插入引发“ascii”编解码器无法在位置 87 编码字符“\xea”:序数不在范围内(128)错误
- r - ggplot辅助轴错误的图例颜色
- docker - 如何使用 sh 打开 Docker 容器中的端口?
- python - 在列表中找到所有的山丘和山谷
- shell - 如何在詹金斯工作区中移动文件?
- excel - PowerPivot how to remove column filter through VBA code
- java - 如何使用 JNA 指针在内存中写入数据?
- regex - 正则表达式中的转义逗号 - Notepad++
- ansible - 如何避免用ansible进行变量替换
- c# - 用于格式错误的 JSON 的自定义 JSON 反序列化器