【问题标题】:Telepot error that keeps appearing again and again不断出现的 Telepot 错误
【发布时间】:2021-04-05 18:58:22
【问题描述】:

我已经为 telegram 群组创建了一个机器人,但是每当有人发送 poll 时,这个错误就会一次又一次地出现..

不断报错的API消息:

{"update_id":869921319,
"poll":{"id":"5427146762856956026","question":"[4/10] Qui \u00e9tait le ma\u00eetre de Grey","options":[{"text":"Oul","voter_count":6},{"text":"Grandin\u00e9","voter_count":0},{"text":"Leon","voter_count":0},{"text":"Mavis","voter_count":2}],"total_voter_count":8,"is_closed":true,"is_anonymous":false,"type":"quiz","allows_multiple_answers":false,"correct_option_id":0}}

我的代码:

import telepot
def on_chat_message(msg):
    try:
        content_type, chat_type, chat_id = telepot.glance(msg)
    except Exception as e:
        return "Oops!", e.__class__, "occurred."
def on_callback_query(msg):
    query_id, chat_id, query_data = telepot.glance(msg, flavor='callback_query')

TOKEN = "BOT TOKEN"
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
                  'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

while 1:
    time.sleep(10)

错误:

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\telepot\loop.py", line 67, in run_forever
    self._update_handler(update)
  File "C:\Python38\lib\site-packages\telepot\loop.py", line 153, in <lambda>
    collectloop.input_queue.put(_extract_message(update)[1]))
  File "C:\Python38\lib\site-packages\telepot\loop.py", line 103, in _extract_message
    key = _find_first_key(update, ['message',
  File "C:\Python38\lib\site-packages\telepot\__init__.py", line 68, in _find_first_key
    raise KeyError('No suggested keys %s in %s' % (str(keys), str(d)))
KeyError: "No suggested keys ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'callback_query', 'inline_query', 'chosen_inline_result', 'shipping_query', 'pre_checkout_query'] in {'update_id': 869921319, 'poll': {'id': '5427146762856956026', 'question': '[4/10] Qui était le maître de Grey', 'options': [{'text': 'Oul', 'voter_count': 6}, {'text': 'Grandiné', 'voter_count': 0}, {'text': 'Leon', 'voter_count': 0}, {'text': 'Mavis', 'voter_count': 2}], 'total_voter_count': 8, 'is_closed': True, 'is_anonymous': False, 'type': 'quiz', 'allows_multiple_answers': False, 'correct_option_id': 0}}"

【问题讨论】:

    标签: python telegram-bot telepot


    【解决方案1】:

    您可能知道,telepot 已经有一段时间没有维护了。在我看来,this pull request 试图解决这个问题,但从未合并。可能不建议继续使用 Telepot。

    不过,您可以查看forks。也许其中之一实际上仍然有效。

    这个问题很可能是由于 Telegram 端 API 的更改,以及 Telepot 中对意外值的不干净处理造成的。

    我自己的机器人最近也因为这样的消息而停止工作。我没有进行太多审查,就切换到this fork - 我不再投资于我的机器人,所以必须这样做。根据您的使用情况,这可能是也可能不是一个好方法。

    如果你选择这样做,那只是一个

    python2.7 -m pip install --user https://github.com/MoumenKhadr/telepot.git
    

    或者只是

    pip install https://github.com/MoumenKhadr/telepot.git
    

    取决于您的设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-09
      • 2013-12-24
      • 1970-01-01
      • 2018-04-28
      • 2022-11-12
      • 2023-03-09
      • 2020-04-30
      • 1970-01-01
      相关资源
      最近更新 更多