HibiKier / zhenxun_bot

基于 Nonebot2 开发,非常可爱的绪山真寻bot
GNU Affero General Public License v3.0
3.35k stars 605 forks source link

更新后启动报错 #1312

Closed soulrewrite closed 1 year ago

soulrewrite commented 1 year ago

系统版本:Ubuntu 20.04

真寻版本:0.1.5.3

错误截图

(zhenxun-bot-gZbNCi6f-py3.9) [root@VM-12-2-centos zhenxunbot]# python3 bot.py Traceback (most recent call last): File "/root/zhenxunbot/bot.py", line 3, in from services.db_context import init, disconnect File "/root/zhenxunbot/services/init.py", line 1, in from .db_context import * File "/root/zhenxunbot/services/db_context.py", line 3, in from tortoise import Tortoise, fields ModuleNotFoundError: No module named 'tortoise'

请大佬看一下

总结一下 1.poetry install 更新依赖 2.配置里的config.py这段更新后有重复内容 image 最简单就是去复制zhenxun_bot/configs/config.py / 3.报错数据库 修改postgresql:// 改成 postgres:// 4.playwright install 日志提醒

qq351959684 commented 1 year ago

楼主解决么 我遇到同样的问题

skynetfly commented 1 year ago

+1

Erlla commented 1 year ago

+1

Erlla commented 1 year ago

手动安装tortoise后 (zhenxun-bot-py3.8)` # python bot.py
Traceback (most recent call last):
File "bot.py", line 3, in
from services.db_context import init, disconnect
File "/myproject/zhenxun_bot-main/services/init.py", line 1, in
from .db_context import *
File "/myproject/zhenxun_bot-main/services/db_context.py", line 3, in
from tortoise import Tortoise, fields
ImportError: cannot import name 'fields' from 'tortoise' (/root/.cache/pypoetry/virtualenvs/zhenxun-bot-3Q5VN4zz-py3.8/lib/python3.8/site-packages/tortoise/init.py)

unknownpop commented 1 year ago

+1

HibiKier commented 1 year ago

有新依赖,重新装下依赖就行了

skynetfly commented 1 year ago

有新依赖,重新装下依赖就进行了 poetry install后启动虚拟环境运行bot.py报错如下

Traceback (most recent call last): File "/home/skynet/zhenxun_bot/bot.py", line 3, in from services.db_context import init, disconnect File "/home/skynet/zhenxun_bot/services/init.py", line 1, in from .db_context import * File "/home/skynet/zhenxun_bot/services/db_context.py", line 8, in from configs.config import address, bind, database, password, port, sql_name, user File "/home/skynet/zhenxun_bot/configs/config.py", line 11 os.popen("cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'") IndentationError: unexpected indent

Erlla commented 1 year ago

依赖装了还是报错,同上

Disappear9 commented 1 year ago

@Erlla @skynetfly 把配置里的 postgresql:// 改成 postgres:// 试试

Erlla commented 1 year ago

@Erlla @skynetfly 把配置里的postgresql://改成postgres://试试

解决了,是语法的问题

我也解决了,删掉几个缩进和一个括号解决了

soulrewrite commented 1 year ago

@Erlla @skynetfly 把配置里的postgresql://改成postgres://试试

解决了,是语法的问题

我也解决了,删掉几个缩进和一个括号解决了

改那11行那里么 能详细说下么

skynetfly commented 1 year ago

@Erlla @skynetfly 把配置里的postgresql://改成postgres://试试

解决了,是语法的问题

我也解决了,删掉几个缩进和一个括号解决了

改那11行那里么 能详细说下么

改成这样: hostip = os.popen("cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'").read().replace("\n","")

XKaguya commented 1 year ago

大佬们知道windows的应该怎么改么?我也是这个报错

Traceback (most recent call last):
  File "G:\PaoPao\ZhenXun_Bot\bot.py", line 3, in <module>
    from services.db_context import init, disconnect
  File "G:\PaoPao\ZhenXun_Bot\services\__init__.py", line 1, in <module>
    from .db_context import *
  File "G:\PaoPao\ZhenXun_Bot\services\db_context.py", line 8, in <module>
    from configs.config import address, bind, database, password, port, sql_name, user
  File "G:\PaoPao\ZhenXun_Bot\configs\config.py", line 11
    os.popen("cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'")
IndentationError: unexpected indent
soulrewrite commented 1 year ago

楼主解决么 我遇到同样的问题

见楼上

soulrewrite commented 1 year ago

大佬们知道windows的应该怎么改么?我也是这个报错

Traceback (most recent call last):
  File "G:\PaoPao\ZhenXun_Bot\bot.py", line 3, in <module>
    from services.db_context import init, disconnect
  File "G:\PaoPao\ZhenXun_Bot\services\__init__.py", line 1, in <module>
    from .db_context import *
  File "G:\PaoPao\ZhenXun_Bot\services\db_context.py", line 8, in <module>
    from configs.config import address, bind, database, password, port, sql_name, user
  File "G:\PaoPao\ZhenXun_Bot\configs\config.py", line 11
    os.popen("cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'")
IndentationError: unexpected indent

应该也是同个问题

HibiKier commented 1 year ago

大佬们知道windows的应该怎么改么?我也是这个报错

Traceback (most recent call last):
  File "G:\PaoPao\ZhenXun_Bot\bot.py", line 3, in <module>
    from services.db_context import init, disconnect
  File "G:\PaoPao\ZhenXun_Bot\services\__init__.py", line 1, in <module>
    from .db_context import *
  File "G:\PaoPao\ZhenXun_Bot\services\db_context.py", line 8, in <module>
    from configs.config import address, bind, database, password, port, sql_name, user
  File "G:\PaoPao\ZhenXun_Bot\configs\config.py", line 11
    os.popen("cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'")
IndentationError: unexpected indent

应该也是同个问题

重新复制一下config.py文件就行了

yichis commented 1 year ago

大佬问下 修改完提示报错为: Traceback (most recent call last): File "/home/zhenxun_bot/bot.py", line 3, in from services.db_context import init, disconnect File "/home/zhenxun_bot/services/init.py", line 1, in from .db_context import * File "/home/zhenxun_bot/services/db_context.py", line 8, in from configs.config import address, bind, database, password, port, sql_name, user File "/home/zhenxun_bot/configs/config.py", line 5, in from .utils import ConfigsManager File "/home/zhenxun_bot/configs/utils/init.py", line 5, in import cattrs ModuleNotFoundError: No module named 'cattrs' 问一下是什么问题 谢谢

ClaraOWS commented 1 year ago

关于报错数据库连接错误,尝试了各种方式修改config.py均无效,请问一下如何解决,谢谢。 报错如下: 03-13 23:45:59 [SUCCESS] nonebot | Running NoneBot... 03-13 23:45:59 [INFO] uvicorn | Started server process [128] 03-13 23:45:59 [INFO] uvicorn | Waiting for application startup. 03-13 23:45:59 [ERROR] uvicorn | Traceback (most recent call last): File "C:\Users\Administrator\Desktop\zhenxun_bot-main\services\db_context.py", line 50, in init await Tortoise.init(db_url=i_bind, modules={"models": MODELS}) NameError: name 'Tortoise' is not defined. Did you mean: 'tortoise'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-KE5KzDFr-py3.10\lib\site-packages\starlette\routing.py", line 671, in lifespan async with self.lifespan_context(app): File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-KE5KzDFr-py3.10\lib\site-packages\starlette\routing.py", line 566, in aenter await self._router.startup() File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-KE5KzDFr-py3.10\lib\site-packages\starlette\routing.py", line 648, in startup await handler() File "C:\Users\Administrator\Desktop\zhenxun_bot-main\services\db_context.py", line 54, in init raise Exception(f"数据库连接错误.... {type(e)}: {e}") Exception: 数据库连接错误.... <class 'NameError'>: name 'Tortoise' is not defined

03-13 23:45:59 [ERROR] uvicorn | Application startup failed. Exiting. ———————————————————————————————————— 似乎找到原因了,我的db_context.py第21行多了个换行,删了就不报连接错误了。

Otakusprpr commented 1 year ago
[
, line 13, in <module>
    nonebot.load_plugins("basic_plugins")
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\nonebot\plugin\load.py", line 45, in load_p
lugins
    return manager.load_all_plugins()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\nonebot\plugin\manager.py", line 168, in lo
ad_all_plugins
    return set(
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\nonebot\plugin\manager.py", line 169, in <g
enexpr>
    filter(None, (self.load_plugin(name) for name in self.available_plugins))
> File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\nonebot\plugin\manager.py", line 145, in lo
ad_plugin
    module = importlib.import_module(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\import
lib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\nonebot\plugin\manager.py", line 233, in ex
ec_module
    super().exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\Administrator\Desktop\zhenxun_bot-main\zhenxun_bot-main\basic_p
lugins\help\__init__.py", line 12, in <module>
    from ._data_source import create_help_img, get_plugin_help
  File "C:\Users\Administrator\Desktop\zhenxun_bot-main\zhenxun_bot-main\basic_p
lugins\help\_data_source.py", line 2, in <module>
    from ._utils import HelpImageBuild
  File "C:\Users\Administrator\Desktop\zhenxun_bot-main\zhenxun_bot-main\basic_p
lugins\help\_utils.py", line 6, in <module>
    from configs.path_config import DATA_PATH, IMAGE_PATH, TEMPLATE_PATH
ImportError: cannot import name 'TEMPLATE_PATH' from 'configs.path_config' (C:\U
sers\Administrator\Desktop\zhenxun_bot-main\zhenxun_bot-main\configs\path_config
.py)
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "exec_sql"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "bot_friend_group"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "set_admin_permissions"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "manager_group"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "clear_data"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "update_friend_group_info
"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "reload_setting"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "super_cmd"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "nickname"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "broadcast"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "init_plugin_config"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "plugin_shop"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "group_handle"
03-14 20:25:35 [SUCCESS] nonebot | Succeeded to import "coser"
03-14 20:25:36 [SUCCESS] nonebot | Succeeded to import "translate"
03-14 20:25:36 [SUCCESS] nonebot | Succeeded to import "epic"
03-14 20:25:37 [SUCCESS] nonebot | Succeeded to import "draw_card"
03-14 20:25:37 [SUCCESS] nonebot | Succeeded to import "send_dinggong_voice"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "word_clouds"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "luxun"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "bilibili_sub"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "open_cases"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "black_word"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "fake_msg"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "quotations"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "query_resource_points"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "material_remind"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "almanac"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "query_role"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "mihoyobbs_sign"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "genshin_sign"
03-14 20:25:38 [SUCCESS] nonebot | Succeeded to import "query_memo"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "bind"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "resin_remind"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "reset_today_query_user_d
ata"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "query_user"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "genshin"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "aconfig"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "gold_redbag"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "dialogue"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "upload_image"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "move_image"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "delete_image"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "send_image"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "image_management"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "statistics_hook"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "statistics_handle"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "statistics"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "search_anime"
03-14 20:25:39 [SUCCESS] nonebot | Succeeded to import "update_picture"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "web_ui"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "check_zhenxun_update"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "bt"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "group_welcome_msg"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "yiqing"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "nbnhhsh"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "wbtop"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "one_friend"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "check"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "poke"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "search_buff_skin_price"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "sign_in"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "mute"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "my_info"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "about"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "white2black_image"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "ai"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "message_handle"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "word_handle"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "word_bank"
03-14 20:25:40 [SUCCESS] nonebot | Succeeded to import "music"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "parse_bilibili_json"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "withdraw"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "self_message"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pix_pass_del_keyword"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pix"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pix_add_keyword"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pix_update"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pix_show_info"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pix_gallery"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "what_anime"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "update_setu"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "send_setu"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "send_setu_"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "pid_search"
03-14 20:25:41 [SUCCESS] nonebot | Succeeded to import "russian"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "update_gocqhttp"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "jitang"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "poetry"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "comments_163"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "cover"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "alapi"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "weather"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "pixiv_rank_search"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "roll"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "search_image"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "fudu"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "lifeRestart"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "zhenxun_plugin_meiriyiju
-main"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "zhenxun_plugin_animetrac
e-main"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "zhenxun_plugin_intercept
_withdraw-main"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "zhenxun_plugin_VMusic-ma
in"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "nonebot_plugin_homonumbe
r-main"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "DeadMansDraw-main"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "crazy_thursday"
03-14 20:25:42 [SUCCESS] nonebot | Succeeded to import "random_cat_gif"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "zhenxun_plugin_ddcheck-m
ain"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "zhenxun_plugins_TZseries
-main"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "withdraw_message_hook"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "other_hook"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "ban_hook"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "auth_hook"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "chkdsk_hook"
03-14 20:25:43 [SUCCESS] nonebot | Succeeded to import "task_hook"
03-14 20:25:43 [SUCCESS] nonebot | Running NoneBot...
03-14 20:25:43 [INFO] uvicorn | Started server process [1604]
03-14 20:25:43 [INFO] uvicorn | Waiting for application startup.
03-14 20:25:43 [ERROR] uvicorn | Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asynci
o\windows_events.py", line 462, in finish_recv
    return ov.getresult()
OSError: [WinError 64] 指定的网络名不再可用。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asynci
o\proactor_events.py", line 280, in _loop_reading
    data = fut.result()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asynci
o\windows_events.py", line 817, in _poll
    value = callback(transferred, key, ov)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asynci
o\windows_events.py", line 466, in finish_recv
    raise ConnectionResetError(*exc.args)
ConnectionResetError: [WinError 64] 指定的网络名不再可用。

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\zhenxun_bot-main\zhenxun_bot-main\service
s\db_context.py", line 50, in init
    await Tortoise.generate_schemas()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\__init__.py", line 640, in generat
e_schemas
    await generate_schema_for_client(connection, safe)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\utils.py", line 31, in generate_sc
hema_for_client
    await generator.generate_from_string(schema)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\base\schema_generator.py"
, line 448, in generate_from_string
    await self.client.execute_script(creation_string)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\base_postgres\client.py",
 line 34, in _translate_exceptions
    return await self._translate_exceptions(func, *args, **kwargs)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\asyncpg\client.py", line
82, in _translate_exceptions
    return await func(self, *args, **kwargs)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\base_postgres\client.py",
 line 150, in execute_script
    async with self.acquire_connection() as connection:
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\base\client.py", line 326
, in __aenter__
    await self.ensure_connection()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\base\client.py", line 322
, in ensure_connection
    await self.client.create_connection(with_db=True)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\asyncpg\client.py", line
59, in create_connection
    self._pool = await self.create_pool(password=self.password, **self._template
)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\tortoise\backends\asyncpg\client.py", line
65, in create_pool
    return await asyncpg.create_pool(None, **kwargs)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\pool.py", line 409, in _async__init
__
    await self._initialize()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\pool.py", line 437, in _initialize
    await first_ch.connect()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\pool.py", line 129, in connect
    self._con = await self._pool._get_new_connection()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\pool.py", line 507, in _get_new_con
nection
    con = await connection.connect(
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\connection.py", line 2092, in conne
ct
    return await connect_utils._connect(
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\connect_utils.py", line 881, in _co
nnect
    return await _connect_addr(
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\connect_utils.py", line 773, in _co
nnect_addr
    return await __connect_addr(params, timeout, True, *args)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\connect_utils.py", line 831, in __c
onnect_addr
    await compat.wait_for(connected, timeout=timeout)
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\asyncpg\compat.py", line 56, in wait_for
    return await asyncio.wait_for(fut, timeout)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asynci
o\tasks.py", line 479, in wait_for
    return fut.result()
asyncpg.exceptions.ConnectionDoesNotExistError: connection was closed in the mid
dle of operation

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\starlette\routing.py", line 671, in lifespa
n
    async with self.lifespan_context(app):
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\starlette\routing.py", line 566, in __aente
r__
    await self._router.startup()
  File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-
bot--1-ZcKUM-py3.9\lib\site-packages\starlette\routing.py", line 648, in startup

    await handler()
  File "C:\Users\Administrator\Desktop\zhenxun_bot-main\zhenxun_bot-main\service
s\db_context.py", line 53, in init
    raise Exception(f"数据库连接错误.... {type(e)}: {e}")
Exception: 数据库连接错误.... <class 'asyncpg.exceptions.ConnectionDoesNotExistE
rror'>: connection was closed in the middle of operation

03-14 20:25:43 [ERROR] uvicorn | Application startup failed. Exiting.

按照上面修改config的方法均未能解决问题,请问有什么办法嘛

lioshushu commented 1 year ago

手动安装tortoise后 (zhenxun-bot-py3.8)` # python bot.py Traceback (most recent call last): File "bot.py", line 3, in from services.db_context import init, disconnect File "/myproject/zhenxun_bot-main/services/init.py", line 1, in from .db_context import * File "/myproject/zhenxun_bot-main/services/db_context.py", line 3, in from tortoise import Tortoise, fields ImportError: cannot import name 'fields' from 'tortoise' (/root/.cache/pypoetry/virtualenvs/zhenxun-bot-3Q5VN4zz-py3.8/lib/python3.8/site-packages/tortoise/init.py)

这个后续是怎么解决的?怎么试了上下文的办法都不行,重新装依赖也没有用 image

解决了,还是重新装了依赖,之前没装上是说poetry.lock里面描述模组的版本与pyproject.toml不匹配,结果更新不成。两个重新复制真寻最新版的就解决了。