I am writing an Airflow DAG to upload some CSV files to my google sheet. But somehow the DAG cannot find the json file that used to provide the credential. I tried to move the json file to many different places but never succeeded. What should I do to make my DAG find the json?
Here are the relating codes:
def upload():
scope = ['https://spreadsheets.google.com/feeds']
dicter = '~/airflow/credential/client_secret.json'
creds = ServiceAccountCredentials.from_json_keyfile_name(dicter, scope)
client = gspread.authorize(creds)
...
# 3. upload both CSV
task_upload = PythonOperator(
task_id='tu',
python_callable=upload
)
The command I used to test my task is:
airflow tasks test CVETaskGenerate tu 2022-8-24
And the error looks like this:
ERROR - Task failed with exception
Traceback (most recent call last):
File "/opt/anaconda3/envs/airflow_env/lib/python3.9/site-packages/airflow/operators/python.py", line 171, in execute
return_value = self.execute_callable()
File "/opt/anaconda3/envs/airflow_env/lib/python3.9/site-packages/airflow/operators/python.py", line 189, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
File "/Users/yifanhuang/airflow/dags/CVEtriageGenerator.py", line 97, in upload
creds = ServiceAccountCredentials.from_json_keyfile_name(dicter, scope)
File "/opt/anaconda3/envs/airflow_env/lib/python3.9/site-packages/oauth2client/service_account.py", line 219, in from_json_keyfile_name
with open(filename, 'r') as file_obj:
FileNotFoundError: [Errno 2] No such file or directory: '~/airflow/credential/client_secret.json'