[英]Schedule library TypeError: the first argument must be callable
I'm trying to make a gmail bot that sends the same message repeatedly in a time period (for example every hour).我正在尝试制作一个 gmail 机器人,它在一段时间内(例如每小时)重复发送相同的消息。 Here's what I did:这是我所做的:
import smtplib
import time
import schedule
sender_email = input("enter ur e-mail: ")
rec_email = input("enter receiver e-mail: ")
password = input("enter your password: ")
message = input("enter message\n-")
def thankyou(sender_email, rec_email, password, message):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender_email, password)
print("login successful")
server.sendmail(sender_email, rec_email, message)
print("sent")
schedule.every().hour.do(thankyou(sender_email, rec_email, password, message))
while 1:
schedule.run_pending()
time.sleep(1)
By passing thankyou(sender_email, rec_email, password, message)
to schedule.every().hour.do()
, you're passing the result of calling thankyou
with those arguments.通过将thankyou(sender_email, rec_email, password, message)
传递给schedule.every().hour.do()
,您将使用arguments 传递调用thankyou
的结果。 Since thankyou
returns nothing, you're doing the equivalent of schedule.every().hour.do(None)
.由于thankyou
没有返回任何内容,因此您所做的相当于schedule.every().hour.do(None)
。 You should instead pass a function, like a lambda function, that calls thankyou
with the arguments you want:你应该传递一个 function,比如 lambda function,它用 ZDBCZEFB11CAA5BDA979D7 调用thankyou
schedule.every().hour.do(lambda: thankyou(sender_email, rec_email, password, message))
it's because your passing schedule.every().hour.do()
the return of thankyou()
, not the function itself, try:这是因为您传递的schedule.every().hour.do()
是thankyou()
) 的返回,而不是 function 本身,请尝试:
schedule.every().hour.do(lambda:thankyou(sender_email, rec_email, password, message))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.