我正在研究一个查询MySQL数据库的DAG,将数据提取并加载到Google云端存储。
我要导出的表包括text,int,float,varchar(20)和varchar(32)数据。
我使用的是airflow v1.8.0。
default_args = {
'owner' : 'tia',
'start_date' : datetime(2018, 1, 4),
'depends_on_past' : False,
'retries' : 1,
'retry_delay':timedelta(minutes=5),
}
dag = DAG('mysql_to_gcs', default_args=default_args)
export_waybills = MySqlToGoogleCloudStorageOperator(
task_id='extract_waybills',
mysql_conn_id = 'podiotestmySQL',
sql = 'SELECT * FROM podiodb.logistics_waybills',
bucket='podio-reader-storage',
filename= 'podio-data/waybills{}.json',
schema_filename='podio-data/schema/waybills.json',
dag=dag)
我突然发现以下错误,这似乎与这个Airflow mysql to gcp Dag error相似
[2018-01-04 11:12:23,372] {models.py:1342}信息 - 执行时间为2018-01-04 00:00:00
[2018-01-04 11:12:23,400] {base_hook.py:67}信息 - 使用连接到:35.189.207.140
[2018-01-04 11:12:24,903] {models.py:1417}错误 - 需要一个类似字节的对象,而不是'str'
Traceback(最近一次调用最后一次):
文件“/home/hyperli/.local/lib/python3.5/site-packages/airflow/models.py”,第1374行,在运行中
result = task_copy.execute(context = context)
文件“/home/hyperli/.local/lib/python3.5/site-packages/airflow/contrib/operators/mysql_to_gcs.py”,第91行,执行
files_to_upload = self._write_local_data_files(cursor)
在_write_local_data_files中输入文件“/home/hyperli/.local/lib/python3.5/site-packages/airflow/contrib/operators/mysql_to_gcs.py”,第136行
json.dump(row_dict,tmp_file_handle)
在转储fp.write(块)中的文件“/usr/lib/python3.5/json/init.py”,第179行
文件“/usr/lib/python3.5/tempfile.py”,第622行,在func_wrapper中返回func(* args,** kwargs)
TypeError:需要类似字节的对象,而不是'str'
[2018-01-04 11:12:24,907] {models.py:1433}信息 - 将任务标记为UP_FOR_RETRY
[2018-01-04 11:12:25,037] {models.py:1462}错误 - 需要一个类似字节的对象,而不是'str'
有谁知道抛出异常的原因?
你在使用python 3吗?因为它接缝mysql_to_gcs的最新版本(1.90)不兼容python接缝。
它接缝这个运算符被更改here以使mysql_to_gcs py3兼容。但latest version(1.90)不包括this change