【问题标题】:Getting exception : AttributeError __aenter__获取异常:AttributeError __aenter__
【发布时间】:2022-10-17 16:56:08
【问题描述】:

我得到这个异常:“发生异常:AttributeError __aenter__”在async with bot: 行。 (我输入了令牌)。请帮忙

import asyncio
import telegram


async def main():
    bot = telegram.Bot("token")
    async with bot:
        print(await bot.get_me())


if __name__ == '__main__':
    asyncio.run(main())

我在这里找到了这段代码:https://github.com/python-telegram-bot/python-telegram-bot/wiki/Introduction-to-the-API

【问题讨论】:

  • 你安装了哪个版本的 python-telegram-bot 包?
  • python-telegram-bot 13.11 |机器人 API 5.7 |证书 2022.05.18.1 | Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 位 (AMD64)]
  • 哦。 github 中的文档适用于 20.x 版本。我得到它

标签: python python-asyncio python-telegram-bot


【解决方案1】:

可能是因为您安装了 python-telegram-bot 13.x 版而出现异常。

尝试:

点冻结

检查一下,如果那是真的,你必须做

pip install python-telegram-bot --pre

因为只有不稳定的版本使用异步。

【讨论】:

    【解决方案2】:

    认为那是因为您安装了 v13(pip install python-telegram-bot),而您正在查看的示例来自 v20 Github wiki。

    前往此处获取 v13 包装器的快速入门指南:https://github.com/python-telegram-bot/v13.x-wiki/wiki/Extensions-%E2%80%93-Your-first-Bot

    【讨论】:

      猜你喜欢
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-11
      • 2013-03-01
      • 2019-05-15
      • 2018-08-14
      • 2012-12-21
      相关资源
      最近更新 更多