我写了一个脚本,发送一封包含每日假期的电子邮件。它在独立运行时工作。我还编写了一个脚本,为它设置了一个自动运行的 cronjob,它正确地设置了一个 cronjob,但电子邮件从不发送。不过,cronjob 确实适用于其他测试脚本。所以这两部分都是独立工作的,只是不适用于电子邮件脚本。我检查了终端邮件,这是出现的错误,我不知道如何解决:
/anaconda3/lib/python3.7/getpass.py:91: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Password for <bggoldberg33@gmail.com>: Traceback (most recent call last):
File "/anaconda3/lib/python3.7/getpass.py", line 69, in unix_getpass
old = termios.tcgetattr(fd) # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')
我对 Python 很陌生,所以任何人都可以帮助解释这意味着什么以及如何解决它?
Python 版本 3.7.3 并使用命令行在 MacOS 10.13.4 上运行
以下是电子邮件和 cron 脚本供参考:
import yagmail
import pandas as pd
from datetime import datetime
# create variables
df = pd.read_excel('/Users/bgoldberg/PythonScripts/FunStuff/holidays.xlsx')
df['DateCheck'] = df['Date'] == datetime.today().strftime('%m/%d')
df = df.loc[df['DateCheck'] == True]
df.reset_index(inplace=True)
if len(df) == 1:
holiday1 = df.at[0, 'Holiday']
link1 = df.at[0, 'Link']
content = f'Happy {holiday1}! {link1}'
elif len(df) > 1:
holiday1 = df.at[0, 'Holiday']
link1 = df.at[0, 'Link']
holiday2 = df.at[1, 'Holiday']
link2 = df.at[1, 'Link']
content = f'Happy {holiday1}! {link1} \nHappy {holiday2}! {link2}'
else:
pass
weekday = datetime.today().strftime('%A')
# create email
receiver = 'bggoldberg33@gmail.com'
body = f'{content}'
yag = yagmail.SMTP('bggoldberg33@gmail.com')
yag.send(
to = receiver,
subject = 'Fun Daily Holidays',
contents = body
)
定时任务:
from crontab import CronTab
my_cron = CronTab(user='bgoldberg')
job = my_cron.new(command='/anaconda3/bin/python3 /Users/bgoldberg/PythonScripts/FunStuff/emailTest.py')
job.minute.every(1)
my_cron.write()