PaiGramTeam / PaiGram

telegram robot, query the official genshin information
GNU Affero General Public License v3.0
84 stars 23 forks source link

[Bug]: ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext' #200

Closed JadeVane closed 1 year ago

JadeVane commented 1 year ago

请确保您已阅读以上注意事项,并勾选下方的确认框。

程序版本 (Commit Id)

54146a97af4a40e25864a29bbd67aba6de84f1cc

运行环境

Ubuntu

运行架构

AMD64

重现步骤

正确安装依赖并修改.env文件配置后运行

alembic upgrade head

期望的结果是什么?

正确初始化数据库

实际的结果是什么?

报错

[2022-10-21 10:11:33] ERROR    在导入文件 "core.sign.models" 的过程中遇到了错误:                                                                                   alembic.env 45   
                               [red bold]ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext'                                                                       
                               (/home/wenjinyu/.local/lib/python3.10/site-packages/telegram/ext/__init__.py)[/]                                                                     
                      ERROR    在导入文件 "core.admin.models" 的过程中遇到了错误:                                                                                  alembic.env 45   
                               [red bold]ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext'                                                                       
                               (/home/wenjinyu/.local/lib/python3.10/site-packages/telegram/ext/__init__.py)[/]                                                                     
                      ERROR    在导入文件 "core.user.models" 的过程中遇到了错误:                                                                                   alembic.env 45   
                               [red bold]ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext'                                                                       
                               (/home/wenjinyu/.local/lib/python3.10/site-packages/telegram/ext/__init__.py)[/]                                                                     
                      ERROR    在导入文件 "core.cookies.models" 的过程中遇到了错误:                                                                                alembic.env 45   
                               [red bold]ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext'                                                                       
                               (/home/wenjinyu/.local/lib/python3.10/site-packages/telegram/ext/__init__.py)[/]                                                                     
                      ERROR    在导入文件 "core.quiz.models" 的过程中遇到了错误:                                                                                   alembic.env 45   
                               [red bold]ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext'                                                                       
                               (/home/wenjinyu/.local/lib/python3.10/site-packages/telegram/ext/__init__.py)[/]                                                                     
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

简单的复现代码/链接(可选)

No response

日志记录(可选)

No response

补充说明(可选)

No response

chuangbo commented 1 year ago

看上去你使用的 Python 可能不是 poetry 管理的。请确认你是使用 poetry install 正确安装了依赖。并且使用 poetry run alembic upgrade head 确保是使用 poetry 的环境执行命令。

也可以尝试一下 poetry run python 然后手动 import AIORateLimiter from telegram.ext 测试。

luoshuijs commented 1 year ago

嗯,我们再次确认, aiolimiter 是存在需求文件上,可能是你安装的时候出现了错误或使用的不是 poetry 导致的。请仔细检查,或重新执行 poetry installhttps://github.com/luoshuijs/TGPaimonBot/blob/57f0029a4202e23d0d957e2a2f8962b7982f8616/pyproject.toml#L15 https://github.com/luoshuijs/TGPaimonBot/blob/57f0029a4202e23d0d957e2a2f8962b7982f8616/poetry.lock#L29-L35

JadeVane commented 1 year ago

感谢回复

运行 poetry install 正常,似乎依赖已经正确安装

Installing dependencies from lock file

No dependencies to install or update

按照 @chuangbo 的方法,我将 alembic upgrade head 改为 poetry run alembic upgrade head 后没有报错

INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

但在最后一步 python ./run.py 启动时仍然报这个错

Traceback (most recent call last):
  File "/home/wenjinyu/Documents/genshin/TGPaimonBot/./run.py", line 1, in <module>
    from core.bot import bot
  File "/home/wenjinyu/Documents/genshin/TGPaimonBot/core/bot.py", line 14, in <module>
    from telegram.ext import (
ImportError: cannot import name 'AIORateLimiter' from 'telegram.ext' (/home/wenjinyu/.local/lib/python3.10/site-packages/telegram/ext/__init__.py)

是没找到 poetry 的执行文件导致的错误吗

其他信息:Python 3.10.4

chuangbo commented 1 year ago

原因是你没有正确激活并使用 poetry 管理的环境。请使用 poetry run python run.py 。

JadeVane commented 1 year ago

跑起来了,第一次接触,确实不了解

不过卡在网络这一步了,有代理相关设置吗

[2022-10-21 10:51:26] INFO     正在初始化BOT                                                                                                                          core.bot 234  
[2022-10-21 10:51:31] WARNING  连接至 telegram 服务器失败,正在重试                                                                                                   core.bot 249  
[2022-10-21 10:51:36] WARNING  连接至 telegram 服务器失败,正在重试                                                                                                   core.bot 249

尝试在终端设置了 http_proxy 变量,似乎不起作用

karakoo commented 1 year ago

跑起来了,第一次接触,确实不了解

不过卡在网络这一步了,有代理相关设置吗

[2022-10-21 10:51:26] INFO     正在初始化BOT                                                                                                                          core.bot 234  
[2022-10-21 10:51:31] WARNING  连接至 telegram 服务器失败,正在重试                                                                                                   core.bot 249  
[2022-10-21 10:51:36] WARNING  连接至 telegram 服务器失败,正在重试                                                                                                   core.bot 249

尝试在终端设置了 http_proxy 变量,似乎不起作用

还需要设置 https_proxy 环境变量

export http_proxy="http://127.0.0.1:xxxx/"
export https_proxy="http://127.0.0.1:xxxx/"
JadeVane commented 1 year ago

已经可以正常运行了,不过看到控制台有不少报错,需要解决吗

ERROR    来自core.template的服务初始化失败:create_template_service() missing 1 required positional argument: 'browser'                     core.service 30
         ...

ERROR    在安装插件 "plugins.genshin.help.HelpPlugin" 的过程中遇到了错误:                                                                       core.bot 124  
         ModuleNotFoundError:
         ...

ERROR    在安装插件 "plugins.genshin.avatar_list.AvatarListPlugin" 的过程中遇到了错误:                                                          core.bot 124  
         TypeError: AvatarListPlugin.__init__() missing 2 required positional arguments: 'assets_service' and 'template_service'
         ...

ERROR    在安装插件 "plugins.genshin.daily.material.DailyMaterial" 的过程中遇到了错误:                                                          core.bot 124  
         TypeError: DailyMaterial.__init__() missing 2 required positional arguments: 'assets' and 'template_service'

省略了大部分,如有必要可以贴上完整日志

另外,有文档展示有哪些可用命令吗?/help /show 之类的全都显示 前面的区域,以后再来探索吧!

chuangbo commented 1 year ago

有可能你没有执行 readme 中提到的安装 chromium 命令。

JadeVane commented 1 year ago

都安装了,而且以为是没装全的问题,还直接运行 playwright install 把 firefox 和 webkit 都装上了

chuangbo commented 1 year ago

也是在 poetry 执行的吗?

poetry run playwright install chromium

JadeVane commented 1 year ago

啊。。。还真不是,再跑一次才装上,但是装上后仍然后上述报错

luoshuijs commented 1 year ago

@JadeVane 报错日记还是一样吗

karakoo commented 1 year ago

啊。。。还真不是,再跑一次才装上,但是装上后仍然后上述报错

发来完整log康康,在项目的log文件夹下的 debug.log 和 error.log

luoshuijs commented 1 year ago

如果不建议,你可以使用 https://fars.ee/ 或者其他日记分享平台发送 log 看看

luoshuijs commented 1 year ago

总感觉是 poetry 自动创建虚拟环境导致的一系列问题。我猜你先用 virtualenv 搞了个虚拟环境,然后在虚拟环境里装了 poetrypoetry 又在里面创建了新虚拟环境安装依赖。

JadeVane commented 1 year ago

error.log:http://fars.ee/yv0U debug.log:http://fars.ee/Utis

JadeVane commented 1 year ago

我猜你先用 virtualenv 搞了个虚拟环境,然后在虚拟环境里装了 poetry ,poetry 又在里面创建了新虚拟环境安装依赖。

我是按照 readme 上的步骤一步步来的,后面提示缺依赖,我就手动安装了一些依赖(例如 ujson),除此之外没有做其他更改,所以这些错误很有可能是少配置了什么而导致的

chuangbo commented 1 year ago

不需要手动安装依赖。我看到你贴的错误提示中有几行

[2022-10-21 11:18:17] ERROR    服务 "AioBrowser" 初始化失败: Executable doesn't exist at /home/wenjinyu/.cache/ms-playwright/chromium-1024/chrome-linux/chrome        core.bot 171  
                               ╔════════════════════════════════════════════════════════════╗                                                                                       
                               ║ Looks like Playwright was just installed or updated.       ║                                                                                       
                               ║ Please run the following command to download new browsers: ║                                                                                       
                               ║                                                            ║                                                                                       
                               ║     playwright install                                     ║                                                                                       
                               ║                                                            ║                                                                                       
                               ║ <3 Playwright Team                                         ║                                                                                       
                               ╚════════════════════════════════════════════════════════════╝                                                                                       

所以还是确认一下 playwright 的浏览器是否正确安装。

JadeVane commented 1 year ago

之前应该是没在poetry环境里面安装,后来运行 poetry run playwright install chromium 就安装上了,那部分日志应该是之前没装的时候产生的

现在运行已经没提示了

thinkpad-e15-gen-2 12:19 (~/Documents/genshin/TGPaimonBot) main $ poetry run playwright install chromium
thinkpad-e15-gen-2 12:25 (~/Documents/genshin/TGPaimonBot) main $ poetry run playwright install
Downloading Firefox 104.0 (playwright build v1350) - 76.5 Mb [===============     ] 77% 10.8s
JadeVane commented 1 year ago

现在是能跑起来,但是不能用。。。

图片

debug.log:https://pastebin.ubuntu.com/p/yXxX6gqNCv/ error log:https://pastebin.ubuntu.com/p/ZcrzZdgfRs/

还是之前的配置出错了吗

luoshuijs commented 1 year ago

@JadeVane 第一次运行需要绑定CK,而不是绑定UID

luoshuijs commented 1 year ago

还有你这个日记太多错误了吧,日记发送的地址可以填写你的 user_id,还有就是你代理似乎没办法请求一些地址。

JadeVane commented 1 year ago

已成功运行,真的很好用!感谢开发!

日记发送的地址可以填写你的 user_id

意思是可以把错误日志直接发到tg吗

你代理似乎没办法请求一些地址

香港服务器,不知是否有影响

luoshuijs commented 1 year ago

@JadeVane 对,是可以发送到TG

luoshuijs commented 1 year ago

@JadeVane 刚刚更新了一下,如果你不想用错误通知,可以吧那行配置注释掉,记得 git pull 即可。

JadeVane commented 1 year ago

好的。还有个问题,请问有更详细的使用教程吗,例如如何获取能够导入祈愿记录的url

Screenshot_20221021-194036~2.png

luoshuijs commented 1 year ago

@JadeVane 发送导入抽卡命令,里面就有帮助

JadeVane commented 1 year ago

我按照那个帮助打开了页面,导入了记录,但是没找到可以用于导入bot的url

luoshuijs commented 1 year ago

剩下话题已经 off topic 很远很远了,如果你还有其他问题可转 discussions 继续讨论。