(Думаю, я также могу использовать SimpleHttpOperator).
В вызываемом методе мне нужно использовать файл конфигурации (director_api.cfg), который содержит учетные данные внешней системы, а также учетные данные для экземпляра Mongo.
Конфигурация файл хранится в сегменте хранилища GCP
Вот код dag:
Код: Выделить всё
from airflow.operators.python import PythonOperator
from airflow import models
from UpdateDirectorDataInMongo import main
# UpdateDirectorDataInMongo.py has the main method which is called in the PythonOperator task. This is stored in the same bucket as the dag file
with models.DAG(
'directorinfo',
# Continue to run DAG twice per day
default_args=default_dag_args,
schedule_interval=None,
catchup=False,
) as dag:
update_director_info = PythonOperator(
task_id="update_director_info",
python_callable=main
)
update_director_info
## UpdateDirectorDataInMongo.py - code where i try to access the director_api.cfg file
import configparser
self.api_username = parser.get("director-api", "user")
self.api_passwd = parser.get("director-api", "passwd")
self.mongoConnUri = parser.get('mongo', 'mongoConnUri') + "?retryWrites=true&w=majority"
# director-api.cfg (location is the same storage bucket as the dag file)
[director-api]
user=
passwd=
[mongo]
mongoConnUri=mongodb+srv://:@cluster..mongodb.net/
Ошибка показана ниже:
Код: Выделить всё
-04, 04:19:13 UTC] {taskinstance.py:1776} ERROR - Task failed with exception
Traceback (most recent call last):
File "/opt/python3.8/lib/python3.8/site-packages/airflow/operators/python.py", line 174, in execute
return_value = self.execute_callable()
File "/opt/python3.8/lib/python3.8/site-packages/airflow/operators/python.py", line 188, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
File "/home/airflow/gcs/dags/UpdateDirectorDataInMongo.py", line 86, in main
customers = getCustomers()
File "/home/airflow/gcs/dags/UpdateDirectorDataInMongo.py", line 72, in getCustomers
mongoConnUri = parser.get('mongo', 'mongoConnUri') + "?retryWrites=true&w=majority"
File "/opt/python3.8/lib/python3.8/configparser.py", line 781, in get
d = self._unify_values(section, vars)
File "/opt/python3.8/lib/python3.8/configparser.py", line 1149, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'mongo'
tia !
Подробнее здесь: https://stackoverflow.com/questions/739 ... -when-usin
Мобильная версия