'can't figure out python indentation error [duplicate]
I am writing some Airflow DAG code in Python 3.8, but there is an indentation error which I am unable to figure out. I use VScode as the IDE
Here is the code:
from airflow_env import DAG
from datetime import datetime
with DAG(
dag_id='user-processing',
schedule_interval='@daily',
start_date=datetime(2022, 1, 1)) as dag:
on the terminal, the error says following: unexpected EOF while parsing
but on the IDE I see expected indented block pylance python
Solution 1:[1]
with DAG(
dag_id='user-processing',
schedule_interval='@daily',
start_date=datetime(2022, 1, 1)) as dag:
This is the beginning of a with/as block, you can't leave it empty, at least you have to specify a pass:
with DAG(...) as dag:
pass
Solution 2:[2]
thank you, it required a task statement to be added as part of with/as block. the error is gone now. I was following a tutorial for DAG where they did not talk about the task statement until few pages later. thank you all for the prompt help
here is the rest of the code:
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime
def helloworld():
print("hello world")
with DAG(
dag_id='user-processing',
schedule_interval='@daily',
start_date=datetime(2022, 1, 1)) as dag:
task1 = PythonOperator(
task_id="hello_world",
python_callable=helloworld
)
task1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | wjandrea |
| Solution 2 | shicha |
