clovers-project / nonebot-plugin-clovers

nonebot_plugin_clovers
MIT License
1 stars 1 forks source link

无法加载插件 #1

Open laiyoi opened 4 months ago

laiyoi commented 4 months ago

环境

nonebot版本2.3.2 系统windows 10 python 3.12.4 在导入别的插件时报错 pydantic 1.10

如果nb plugin update clover,就会安装1.8的pydantic,别的插件不能用 nb2文档中给出

NoneBot 自 2.2.0 起兼容了 Pydantic v1 与 v2 版本,以下文档中 Pydantic 相关示例均采用 v2 版本用法。

如果在使用商店或其他第三方插件的过程中遇到 Pydantic 相关警告或报错,例如:

pydantic_core._pydantic_core.ValidationError: 1 validation error for Config
  Input should be a valid dictionary or instance of Config [type=model_type, input_value=Config(...), input_type=Config]
请考虑降级 Pydantic 至 v1 版本:

pip install --force-reinstall 'pydantic~=1.10'

日志:

Traceback (most recent call last):
  File "e:\nb\test\bot.py", line 16, in <module>
    nonebot.load_from_toml("pyproject.toml")
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot\plugin\load.py", line 131, in load_from_toml
    return load_all_plugins(plugins, plugin_dirs)
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot\plugin\load.py", line 65, in load_all_plugins
    return manager.load_all_plugins()
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot\plugin\manager.py", line 203, in load_all_plugins
    return set(
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot\plugin\manager.py", line 204, in <genexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "e:\anaconda\envs\nb\Lib\site-packages\nonebot\plugin\manager.py", line 167, in load_plugin
    module = importlib.import_module(self._third_party_plugin_ids[name])
  File "e:\anaconda\envs\nb\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot\plugin\manager.py", line 255, in exec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot_plugin_game_collection\__init__.py", line 2, in <module>
    from nonebot_plugin_clovers import clovers
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot_plugin_clovers\__init__.py", line 43, in <module>
    clovers_config_data = ConfigClovers.model_validate(clovers_config.get(config_key, {}))
AttributeError: type object 'ConfigClovers' has no attribute 'model_validate'
KarisAya commented 4 months ago

Screenshot_2024-07-10-09-02-04-849_com android browser-edit 此插件使用了pydantic2.0才有的方法。所以降级pydantic会导致报错。

laiyoi commented 4 months ago

安装pydantic2.7.1出现另一种报错

  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot_plugin_game_collection\__init__.py", line 2, in <module>
    from nonebot_plugin_clovers import clovers
  File "e:\anaconda\envs\nb\Lib\site-packages\nonebot_plugin_clovers\__init__.py", line 43, in <module>
    clovers_config_data = ConfigClovers.model_validate(clovers_config.get(config_key, {}))
  File "e:\anaconda\envs\nb\Lib\site-packages\pydantic\main.py", line 551, in model_validate
    return cls.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 1 validation error for ConfigClovers
  Input should be a valid dictionary or instance of ConfigClovers [type=model_type, input_value='{"plugins_path": "./clov...y", "plugins_list": []}', input_type=str]
    For further information visit https://errors.pydantic.dev/2.7/v/model_type
KarisAya commented 4 months ago

nonebot_plugin_clovers版本是什么

KarisAya commented 4 months ago

配置应该是toml键值对,你的配置为什么变成字符串了 配置加载使用的代码是toml.load(path),理应读到字典才对

laiyoi commented 4 months ago

image