커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
확인부탁합니다.
[왕초보] ChatGPT 300% 활용하기 v0
4주차
북마크
정*욱
댓글
7
추천
0
조회수
8
조회수
8
답변 완료

ㅜ* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


customer_data_test.xlsx의 경로를 복사해서 해결되었는데 스케쥴러 설정후 다시 아래와같은 에러가 발생됩니다



import openpyxl

import smtplib

from email.mime.text import MIMEText

from email.mime.multipart import MIMEMultipart

import schedule

import time


def send_email():

  # Gmail SMTP 서버 설정

  smtp_server = 'smtp.gmail.com'

  smtp_port = 587

  smtp_username = 'test@gmail.com'

  smtp_password = 'app_password'


  # Excel 파일에서 이름과 이메일 추출

  wb = openpyxl.load_workbook('customer_data_test.xlsx')

  ws = wb['test_name_email']


  name_list = []

  email_list = []


  for row in ws.iter_rows(min_row=2, values_only=True):

    name = row[0]

    email = row[1]

    name_list.append(name)

    email_list.append(email)


  # Gmail 서버 연결

  with smtplib.SMTP(smtp_server, smtp_port) as smtp:

    smtp.starttls()

    smtp.login(smtp_username, smtp_password)


    for name, email in zip(name_list, email_list):

      # 메일 제목, 본문 내용 작성

      mail_subject = f'[{name}] 자그마한 선물을 받으세요!'

      mail_body = f'안녕하세요 {name}님,\n\n저희 앱을 이용해주셔서 감사합니다. {name}님이 우리 앱에 10번 이상 로그인하시면 자그마한 선물을 드립니다! 하루에 최대 1번 로그인 가능합니다. 많은 이용 부탁드립니다.\n\n감사합니다.\n\n- salemale 팀'


      # 메일 생성

      message = MIMEMultipart()

      message['From'] = smtp_username

      message['To'] = email

      message['Subject'] = mail_subject


      # 메일 본문 추가

      message.attach(MIMEText(mail_body))


      # 메일 전송

      smtp.send_message(message)


# 스케쥴러 설정

schedule.every(60).minutes.do(send_email)


while True:

  schedule.run_pending()

  time.sleep(1)보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.




작성한 코드 및 에러 메세지

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-47-cb18983dbfbf> in <cell line: 53>()
     52 
     53 while True:
---> 54     schedule.run_pending()
     55     time.sleep(1)


8 frames

/usr/lib/python3.10/zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
   1249             while True:
   1250                 try:
-> 1251                     self.fp = io.open(file, filemode)
   1252                 except OSError:
   1253                     if filemode in modeDict:

FileNotFoundError: [Errno 2] No such file or directory: 'customer_data_test.xlsx'


오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.

Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.

Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴