我正在尝试在Telegram中发布自动时间表。它首先运行,但在尝试循环后我得到一个错误:
TypeError:第一个参数必须是可调用的
我的代码:
import time
import schedule
from pyrogram import Client, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.api import functions, types
from pyrogram.api.errors import FloodWait
person1 = Client(
session_name="*cenzored*",
api_id=*cenzored*,
api_hash="*cenzored*"
)
person2 = Client(
session_name="*cenzored*",
api_id=*cenzored*,
api_hash="*cenzored*"
)
wick.start()
def Publish(session,dat,msgid,session_name):
try:
session.start()
print("[%s]Posting..." % (session_name))
session.send(
functions.messages.GetBotCallbackAnswer(
peer=session.resolve_peer("*cenzored*"),
msg_id=msgid,
data=b'publish %d' % (dat)
)
)
session.idle()
except:
print("Crashed,starting over")
schedule.every(0.3).minutes.do(Publish(person1,142129,12758, 'Dani')) // Here is the line is crashing.
schedule.every(0.3).minutes.do(Publish(person2,137351,13177, 'Wick'))
while 1:
schedule.run_pending()
time.sleep(1)
追溯:
Pyrogram v0.7.4, Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
[person1]Posting...
3: 2018-06-16 12:07:26.529829 Retrying <class 'pyrogram.api.functions.messages.get_bot_callback_answer.GetBotCallbackAnswer'>
4: 2018-06-16 12:07:42.041309 Retrying <class 'pyrogram.api.functions.messages.get_bot_callback_answer.GetBotCallbackAnswer'>
Crashed,starting over
Traceback (most recent call last):
File "C:\Users\343df\OneDrive\Desktop\Maor\python\tele\tele.py", line 35, in <module>
schedule.every(0.3).minutes.do(Publish('ss',dani,140129,12758, 'Dani'))
File "C:\Program Files (x86)\Python36-32\lib\site-packages\schedule\__init__.py", line 385, in do
self.job_func = functools.partial(job_func, *args, **kwargs)
TypeError: the first argument must be callable
基本上我的问题是第一次没有运行(TypeError: the first argument must be callable
)并且计划每0.3秒运行一次。
答案 0 :(得分:1)
根据[ReadTheDocs]: do(job_func, *args, **kwargs),您不必调用 发布,但只需传递它,然后是其参数列表(将执行调用)通过 schedule 框架):
schedule.every(0.3).minutes.do(Publish, person1, 142129, 12758, "Dani")
schedule.every(0.3).minutes.do(Publish, person2, 137351, 13177, "Wick")
答案 1 :(得分:1)
.do()
expects一个可调用的第一个参数(.do
的其他参数将被传递给该可调用的。)
所以而不是:
schedule.every(0.3).minutes.do(Publish(person1,142129,12758, 'Dani'))
schedule.every(0.3).minutes.do(Publish(person2,137351,13177, 'Wick'))
你可能想要:
schedule.every(0.3).minutes.do(Publish, person1, 142129, 12758, 'Dani')
schedule.every(0.3).minutes.do(Publish, person2, 137351, 13177, 'Wick')