인프런 커뮤니티 질문&답변

지수님의 프로필 이미지
지수

작성한 질문수

Airflow 마스터 클래스

Email Operator로 메일 전송하기 실패

작성

·

605

0

Email Operator로 메일 전송하기 강의 실습을 진행하다가 에러가 나서 질문 남깁니다.

dag 실행 로그가 아래와 같이 찍히고, 실패 하는데 어떤 부분이 잘못되어서 이런 건지 모르겠습니다...

[2023-11-15, 14:06:59 UTC] {warnings.py:109} WARNING - /home/***/.local/lib/python3.8/site-packages/***/utils/email.py:154: RemovedInAirflow3Warning: Fetching SMTP credentials from configuration variables will be deprecated in a future release. Please set credentials using a connection instead. 
[2023-11-15, 14:06:59 UTC] {configuration.py:1050} WARNING - section/key [smtp/smtp_user] not found in config 
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1937} ERROR - Task failed with exception 
[2023-11-15, 14:06:59 UTC] {standard_task_runner.py:104} ERROR - Failed to execute job 73 for task send_email_task ([Errno 99] Cannot assign requested address; 618)

 

답변 1

0

김현진님의 프로필 이미지
김현진
지식공유자

안녕하세요 지수님

올려주신것만으로는 판단이 어려운데, 원인을 확인하려면

dag내용이랑 에러 전체로그, connection 을 어떻게 등록하셨는지 올려주시겠어요?

 

지수님의 프로필 이미지
지수
질문자

넵 이렇게 드리면 될까요??

dag 내용

import datetime
import pendulum

from airflow import DAG
from airflow.operators.email import EmailOperator

with DAG(
  dag_id="dags_email_operator",
  schedule="0 8 1 * *",
  start_date=pendulum.datetime(2023, 3, 1, tz="Asia/Seoul"),
  catchup=False
) as dag:
  
  send_email_task = EmailOperator(
    task_id="send_email_task",
    to="jjoo4956@naver.com",
    subject="Airflow 성공 메일",
    html_content="Airflow 작업이 완료되었습니다."
  )

 

에러 전체로그

2df86e82d8c2
*** Found local files:
***   * /opt/airflow/logs/dag_id=dags_email_operator/run_id=manual__2023-11-15T14:06:57.712917+00:00/task_id=send_email_task/attempt=1.log
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1159} INFO - Dependencies all met for dep_context=non-requeueable deps ti=<TaskInstance: dags_email_operator.send_email_task manual__2023-11-15T14:06:57.712917+00:00 [queued]>
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1159} INFO - Dependencies all met for dep_context=requeueable deps ti=<TaskInstance: dags_email_operator.send_email_task manual__2023-11-15T14:06:57.712917+00:00 [queued]>
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1361} INFO - Starting attempt 1 of 1
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1382} INFO - Executing <Task(EmailOperator): send_email_task> on 2023-11-15 14:06:57.712917+00:00
[2023-11-15, 14:06:59 UTC] {standard_task_runner.py:57} INFO - Started process 618 to run task
[2023-11-15, 14:06:59 UTC] {standard_task_runner.py:84} INFO - Running: ['***', 'tasks', 'run', 'dags_email_operator', 'send_email_task', 'manual__2023-11-15T14:06:57.712917+00:00', '--job-id', '73', '--raw', '--subdir', 'DAGS_FOLDER/dags_email_operator.py', '--cfg-path', '/tmp/tmpa9vg4uqd']
[2023-11-15, 14:06:59 UTC] {standard_task_runner.py:85} INFO - Job 73: Subtask send_email_task
[2023-11-15, 14:06:59 UTC] {task_command.py:416} INFO - Running <TaskInstance: dags_email_operator.send_email_task manual__2023-11-15T14:06:57.712917+00:00 [running]> on host 2df86e82d8c2
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1662} INFO - Exporting env vars: AIRFLOW_CTX_DAG_OWNER='***' AIRFLOW_CTX_DAG_ID='dags_email_operator' AIRFLOW_CTX_TASK_ID='send_email_task' AIRFLOW_CTX_EXECUTION_DATE='2023-11-15T14:06:57.712917+00:00' AIRFLOW_CTX_TRY_NUMBER='1' AIRFLOW_CTX_DAG_RUN_ID='manual__2023-11-15T14:06:57.712917+00:00'
[2023-11-15, 14:06:59 UTC] {warnings.py:109} WARNING - /home/***/.local/lib/python3.8/site-packages/***/utils/email.py:154: RemovedInAirflow3Warning: Fetching SMTP credentials from configuration variables will be deprecated in a future release. Please set credentials using a connection instead.
  send_mime_email(e_from=mail_from, e_to=recipients, mime_msg=msg, conn_id=conn_id, dryrun=dryrun)
[2023-11-15, 14:06:59 UTC] {configuration.py:1050} WARNING - section/key [smtp/smtp_user] not found in config
[2023-11-15, 14:06:59 UTC] {email.py:270} INFO - Email alerting: attempt 1
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1937} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/operators/email.py", line 77, in execute
    send_email(
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/email.py", line 80, in send_email
    return backend(
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/email.py", line 154, in send_email_smtp
    send_mime_email(e_from=mail_from, e_to=recipients, mime_msg=msg, conn_id=conn_id, dryrun=dryrun)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/email.py", line 272, in send_mime_email
    smtp_conn = _get_smtp_connection(smtp_host, smtp_port, smtp_timeout, smtp_ssl)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/email.py", line 316, in _get_smtp_connection
    return smtplib.SMTP(host=host, port=port, timeout=timeout)
  File "/usr/local/lib/python3.8/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.8/smtplib.py", line 310, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/local/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/local/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address
[2023-11-15, 14:06:59 UTC] {taskinstance.py:1400} INFO - Marking task as FAILED. dag_id=dags_email_operator, task_id=send_email_task, execution_date=20231115T140657, start_date=20231115T140659, end_date=20231115T140659
[2023-11-15, 14:06:59 UTC] {standard_task_runner.py:104} ERROR - Failed to execute job 73 for task send_email_task ([Errno 99] Cannot assign requested address; 618)
[2023-11-15, 14:07:00 UTC] {local_task_job_runner.py:228} INFO - Task exited with return code 1
[2023-11-15, 14:07:00 UTC] {taskinstance.py:2778} INFO - 0 downstream tasks scheduled from follow-on schedule check

 

docker-compose.yaml
image

김현진님의 프로필 이미지
김현진
지식공유자

지수님 SMTP PORT를 587로 입력해야할 듯 한데

포트 번호가 잘못들어간 것 같아요. 589 --> 587로 수정하고 airflow 재기동해보실래요?

 

지수님의 프로필 이미지
지수
질문자

앗! 넵 말씀해주신대로 수정해서 해보니 잘 동작합니다! 감사합니다!

김현진님의 프로필 이미지
김현진
지식공유자

결과가 어떻게 됐나 궁금했는데 해결되어서 다행이네요 ^^

지수님의 프로필 이미지
지수

작성한 질문수

질문하기