【问题标题】:Telegram TypeError: the first argument must be callableTelegram TypeError:第一个参数必须是可调用的
【发布时间】:2018-06-16 09:16:52
【问题描述】:

我正在尝试在 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 秒运行一次。

【问题讨论】:

  • @roganjosh 添加了

标签: python arguments scheduled-tasks telegram


【解决方案1】:

根据[ReadTheDocs]: do(job_func, *args, **kwargs),您不必调用 Publish,只需传递它,然后是它的参数列表(调用将由schedule 框架):

schedule.every(0.3).minutes.do(Publish, person1, 142129, 12758, "Dani")
schedule.every(0.3).minutes.do(Publish, person2, 137351, 13177, "Wick")

【讨论】:

    【解决方案2】:

    .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')
    

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2021-03-20
      • 2020-08-31
      • 2017-06-27
      • 1970-01-01
      • 2020-03-29
      • 2017-05-08
      • 1970-01-01
      • 2018-08-11
      相关资源
      最近更新 更多